cmhughes / latexindent.pl

Perl script to add indentation (leading horizontal space) to LaTeX files. It can modify line breaks before, during and after code blocks; it can perform text wrapping and paragraph line break removal. It can also perform string-based and regex-based substitutions/replacements. The script is customisable through its YAML interface.
GNU General Public License v3.0
864 stars 84 forks source link

Format tabular for fullwidth fonts #540

Closed rikutons closed 3 months ago

rikutons commented 3 months ago

Some characters have larger width than other characters. For example, all CJK characters are fullwidth font. But now latexindent treats these characters as 1-width , that makes shifted \ and & on tabular environment.

Can you add an option to treat fullwidth characters as 2-width characters?

original .tex code

\begin{tabular}{cc}
  a   & aaa \\
  abc & aaaaaa \\
  a   & あああ \\
\end{tabular}

yaml settings

none

actual/given output

\begin{tabular}{cc}
  a   & aaa    \\
  abc & aaaaaa \\
  a   & あああ    \\
\end{tabular}

desired or expected output

\begin{tabular}{cc}
  a   & aaa    \\
  abc & aaaaaa \\
  a   & あああ \\
\end{tabular}

(Seems like Github is not using monospace font on codeblock for fullwidth char,
so I add screenshot with proper monospace font) image

anything else

https://metacpan.org/pod/Text::CharWidth can detect char's width. But idk how to use with that algorithm. So need help to implement if this feature got accepted. https://github.com/cmhughes/latexindent.pl/blob/9cc2d864322c3edf8780d49aa27ba2eb3948e3af/LatexIndent/AlignmentAtAmpersand.pm#L1781

Long fullwidth string makes table broken(It's already formatted). image

cmhughes commented 3 months ago

Can you try the GCString switch

https://latexindentpl.readthedocs.io/en/latest/sec-appendices.html#the-gcstring-switch

rikutons commented 3 months ago

Can you try the GCString switch

https://latexindentpl.readthedocs.io/en/latest/sec-appendices.html#the-gcstring-switch

It worked correctly! I should have read docs more deeply, thanks for advise.