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
884 stars 84 forks source link

Preventing indentation of in macro after newline #385

Closed sw-dbrown closed 2 years ago

sw-dbrown commented 2 years ago

original .tex code

xxxx-xxxxxxxxxxxxxx xxxxxx xxxxxxxxxx, xx xxxx xxxxxxxxxxx xxxxxxxx \emph{xxx
xxx xxx} xxxxx xxxxxxxxxxxxx, xxxxxxxxxxxxxx xxx xxxxxxxxxx xxx xxxxxxxxxx
xxxxxxxx xxx xxxxxxxxxxxxxxxxxxx xxxxx xxx xxxxxxxx xxx xxxxx xxx xxx
xxxxxxxxxxx xxxxxxxxxxx.

yaml settings

I do have custom settings but the shown indentation stems from the default configuration. I can reproduce it with --onlydefault.

actual/given output

xxxx-xxxxxxxxxxxxxx xxxxxx xxxxxxxxxx, xx xxxx xxxxxxxxxxx xxxxxxxx \emph{xxx
    xxx xxx} xxxxx xxxxxxxxxxxxx, xxxxxxxxxxxxxx xxx xxxxxxxxxx xxx xxxxxxxxxx
xxxxxxxx xxx xxxxxxxxxxxxxxxxxxx xxxxx xxx xxxxxxxx xxx xxxxx xxx xxx
xxxxxxxxxxx xxxxxxxxxxx.

desired or expected output

xxxx-xxxxxxxxxxxxxx xxxxxx xxxxxxxxxx, xx xxxx xxxxxxxxxxx xxxxxxxx \emph{xxx
xxx xxx} xxxxx xxxxxxxxxxxxx, xxxxxxxxxxxxxx xxx xxxxxxxxxx xxx xxxxxxxxxx
xxxxxxxx xxx xxxxxxxxxxxxxxxxxxx xxxxx xxx xxxxxxxx xxx xxxxx xxx xxx
xxxxxxxxxxx xxxxxxxxxxx.

(the same as the original tex code)

anything else

Specifically I would like to not have \emph{} (and potentially other) macros indented when they contain a newline. Thank you for your tool and your time!

cmhughes commented 2 years ago

Thanks for this :)

Does the following help:

https://latexindentpl.readthedocs.io/en/latest/sec-default-user-local.html#commands-with-arguments

cmhughes commented 2 years ago

See also

https://latexindentpl.readthedocs.io/en/latest/sec-default-user-local.html#summary

cmhughes commented 2 years ago

More details....

option 1 (emph only)

Using

noAdditionalIndent:
    emph: 1

gives

xxxx-xxxxxxxxxxxxxx xxxxxx xxxxxxxxxx, xx xxxx xxxxxxxxxxx xxxxxxxx \emph{xxx
xxx xxx} xxxxx xxxxxxxxxxxxx, xxxxxxxxxxxxxx xxx xxxxxxxxxx xxx xxxxxxxxxx
xxxxxxxx xxx xxxxxxxxxxxxxxxxxxx xxxxx xxx xxxxxxxx xxx xxxxx xxx xxx
xxxxxxxxxxx xxxxxxxxxxx.

but this will only apply to the emph command.

option 2 (global commands)

Using

noAdditionalIndentGlobal:
    mandatoryArguments: 1

gives the same output

xxxx-xxxxxxxxxxxxxx xxxxxx xxxxxxxxxx, xx xxxx xxxxxxxxxxx xxxxxxxx \emph{xxx
xxx xxx} xxxxx xxxxxxxxxxxxx, xxxxxxxxxxxxxx xxx xxxxxxxxxx xxx xxxxxxxxxx
xxxxxxxx xxx xxxxxxxxxxxxxxxxxxx xxxxx xxx xxxxxxxx xxx xxxxx xxx xxx
xxxxxxxxxxx xxxxxxxxxxx.

but this applies to all mandatory arguments.

cmhughes commented 2 years ago

Let me know if you need anything further :)

sw-dbrown commented 2 years ago

@cmhughes Sorry for the late reply and thank you very much for your time! Your suggestion is exactly what I was looking for and it works as expected.