SYSTEM NOTICE

Auto translation by AI. Be sure, accuracy, nuances and authorial intent may not be fully reflected.
見出し画像

[Automation Tool Course #4] Major Update to the note Table Creation Tool: 'CSV to LaTeX Table Converter Chrome Extension'

Hello everyone, this is rorosuke.

Last time, I released a Chrome extension that converts CSV data in the note editor into LaTeX tags to display tables. You can find it here.

I previously announced updates including TSV/Markdown support, special character escaping, and fixes for top border issues. I have now implemented these updates as promised, and they are already live.

You can install it here.

In addition to what I announced, I have made various other improvements, which I have summarized below.

  • Support for TSV (tab-separated) data

  • Support for Markdown tables

  • Automatic escaping of special characters

  • Enhanced top border option

  • Reverse conversion to CSV, TSV, and Markdown

  • Copy function for Excel and alphanumeric font selection (Gothic/Mincho)

The last feature regarding data exchange with Excel was added as a bonus, but it might be more useful than I imagined.

New tool dialog

When you launch the updated version, the following dialog will appear. Several items have been added, but the basic usage remains the same.

New version dialog

Automatic support for TSV and Markdown tables

TSV is tab-separated data. Markdown is data written in Markdown notation.

TSV

項目	数
リンゴ	1個
バナナ	3個

Markdown

| 項目 | 数 |
|---|---|
| リンゴ | 1個 |
| バナナ | 3個 |

You can convert these types of data into tables.

Tab-separated values are the format saved to the clipboard when you select and copy a range of cells from Excel data. In other words, if you paste this into the note editor as plain text, you can convert it directly to LaTeX using this tool.

Markdown is also supported in the same way.
For example, when you ask an AI to create content for note and request it to 'output in Markdown notation,' tables will also be displayed in Markdown format. While note does not have a built-in feature to render Markdown tables, you can easily convert them into tables using this tool.

Since the tool automatically detects both TSV and Markdown, the operation is the same as with CSV: simply select the text and choose the table style.



Automatic Escaping of Special Characters

In LaTeX, certain special characters are assigned specific functions, which means they sometimes cannot be displayed as-is. One of these is %. In LaTeX, this functions as a comment-out character, so converting it will break the table.

For example, if you have data that says '10%', and you convert it into a table as-is, the cell will only display '10'. To display the '%' symbol itself, you need a way to disable the function assigned to it (escaping).

I have now added a process to batch-escape LaTeX special characters. The target characters are as follows:

% _ ^ # $ & { } ~ \

Even if these are included in the text within a table, they are now automatically escaped so that the characters themselves are displayed.

Additionally, assuming there may be cases where you do not want to escape them, I have made it possible to toggle escaping on and off. It is on by default, but please turn it off if you wish to convert without escaping.

| 項目 | 割引率 |
|---|---|
| リンゴ | 10% |
| バナナ | 30% |

Even if there is a '%', it will be displayed as follows:

$$
\begin{array}{|c|c|}
\\[-1.15em]\hline
\textsf{\small{Item}} & \textsf{\small{Discount Rate}}
\\ \hline
\textsf{\small{Apple}} & \textsf{\small{10\%}}
\\ \hline
\textsf{\small{Banana}} & \textsf{\small{30\%}}
\\ \hline
\end{array}
$$

Exception:I will explain the slightly special pattern where two underscores are placed before and after a word, like __snake__. In this case, when pasted into note, the note editor processes it as Markdown bold text, and the underscores disappear. This is a specification of the note editor, so this tool cannot handle it. Please manually enter the underscores before and after the word after pasting.



Top Border Enhancement

In the previous article, I wrote, 'The top border sometimes appears and sometimes doesn't. I am currently considering what to do about it.'

Regarding how the borders appear, the underlying logic is still not well understood. The preview sometimes differs from the actual display, and the way it is displayed seems unstable depending on the viewing medium. For example, the border might be missing on a PC browser but appear on a smartphone browser.

Since there is no clear rule at this time, I have made it possible to choose whether or not to include '\\[-1.15em]\hline'. You can toggle it on/off with a checkbox. It is set to on by default.



Full Mutual Conversion

Select multiple lines of LaTeX-coded text and click the extension icon to display the following conversion menu.

When you select LaTeX code and invoke the extension,
the conversion menu will appear.

You can now reverse-convert to the following output formats.

  • CSV

  • TSV

  • Markdown

By repeating the conversion, you can cycle through data formats like
CSV → LaTeX → Markdown → LaTeX → TSV
.



Excel Integration

Since tables are synonymous with Excel, I have made it easy to exchange data with it. To achieve this, I added the "Copy for Excel" menu to both the forward conversion menu (when CSV/TSV/Markdown is selected) and the reverse conversion menu (when LaTeX is selected).

Copy for Excel

.

While the standard "Convert back to TSV" inserts text into the note editor, "Copy for Excel" saves the TSV data directly to the clipboard. This allows you to paste it directly into Excel.

Select a table (either before or after conversion) and
choose "Copy for Excel" to save it to the clipboard
You can then paste it directly into Excel

When copying tables for Excel that contain line breaks within cells (specified as ;; in this tool), the ;; is converted into Excel's internal cell line breaks. Conversely, if you paste data containing Excel cell line breaks into note as plain text and select it, it will be recognized as ;; and converted to LaTeX.

Note: Patterns where pasting into Excel may fail
If you paste while an Excel cell has a dotted border (copy standby state), Excel's internal clipboard may take priority, and the expected data might not be pasted. Please press the Esc key to clear the dotted border before pasting with Ctrl+V.



Alphanumeric font selection

When converting to LaTeX, you can now choose between Gothic (sans-serif) and Mincho (serif) fonts for alphanumeric characters. The default is Gothic.

Gothic

$$
\begin{array}{cc}
\\[-1.15em]\hline
\textsf{\small{apple}} & \textsf{\small{\$10}}
\\ \hline
\textsf{\small{banana}} & \textsf{\small{\$30}}
\\ \hline
\end{array}
$$

Mincho

$$
\begin{array}{cc}
\\[-1.15em]\hline
\textrm{\small{apple}} & \textrm{\small{\$10}}
\\ \hline
\textrm{\small{banana}} & \textrm{\small{\$30}}
\\ \hline
\end{array}
$$

Note: Japanese is not supported
This setting applies only to alphanumeric characters. Japanese fonts are outside the scope of KaTeX management and are therefore not supported. It is effective when used for tables containing only alphanumeric characters or tables with a large amount of alphanumeric data.



Summary: Isn't mutual conversion great?

In note, creating tables is a rather troublesome issue when writing articles. Currently, the only way to represent them inline is to write them in LaTeX.

However, by using this tool, you can at least perform mutual conversion between CSV, TSV, Markdown, and Excel, which I believe will make it much easier to actively use tables.

I originally didn't plan to implement mutual conversion, but as I was building it, I decided to implement it because I thought it would increase versatility. At first, repeating conversion and reverse conversion would destroy the data, and I was worried about what would happen, but I managed to get it together.

So, I hope you will use this tool as a 'hub for all table data'.

That is all.

いいなと思ったら応援しよう!

ROROSUKE LABO 記事なり、プログラムなりが役に立ったと思った方は、 チップの応援よろしくお願いいたします。 次の開発もがんばろうかな、という気になりますのだ (笑)