In macros it makes sense to put percent signs at the end of line in order to avoid any line break characters in the macro definition. For example, a macro with a multi-line definition could look like this:
\newcommand{\provideName}[3]{%
\providecommand{#1}{#2}%
\addto\captionsenglish{\renewcommand{#1}{#2}}%
\addto\captionsngerman{\renewcommand{#1}{#3}}%
}
Now I use the latexindent tool to format my code automatically. Usually, this works pretty well but in this case the formatted code looks like:
\newcommand{\provideName}[3]{%
\providecommand{#1}{#2}%
\addto\captionsenglish{\renewcommand{#1}{#2}}%
\addto\captionsngerman{\renewcommand{#1}{#3}}%
}
Why are those extra newlines generated? And how can I turn off this behavior? (The percent signs are common practice, right? Or can I safely remove them?)
localSettings.yaml
defaultIndent: ' '
onlyOneBackUp: 1
modifyLineBreaks:
textWrapOptions:
columns: 78
latexindent parameters
latexindent -w -m --cruft=build --local=./localSettings.yaml myfile.sty
Updated localSettings.yaml
As suggested by cmhughes, I added the perCodeBlockBasis option to get:
defaultIndent: ' '
onlyOneBackUp: 1
modifyLineBreaks:
textWrapOptions:
columns: 78
perCodeBlockBasis: 1
This results in the following code under texlive-2017:
\newcommand{\provideName}[3]{%
\providecommand{#1}{#2}%
\addto\captionsenglish{\renewcommand{#1}{#2}}%latexindenttrailingcomment36-EN
D
\addto\captionsngerman{\renewcommand{#1}{#3}}%latexindenttrailingcomment37-EN
D
}
\provideNamecan occur only in the preamble then you can remove them; otherwise not. See also What is the use of percent signs (%) at the end of lines? – campa Dec 10 '19 at 14:28latexindentin my life. But running it on this snippet does not yield the result you show. Sorry, can't help there... – campa Dec 10 '19 at 14:39latexindent.exe myfile.texthen I don't receive any new blank lines. Can you post complete details of the settings that you're using? The script shouldn't modify line breaks unless you're calling it with the-mswitch, and even then, you would have to specify some settings to receive the output you're getting. Please post your settings files, and the way that you're calling the script and I'll do my best to help :) – cmhughes Dec 10 '19 at 19:07perCodeBlockBasis: 1https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html#lst-textwrap3-yaml – cmhughes Dec 10 '19 at 21:46perCodeBlockBasis: 1, which is the desired behavior. Thanks a lot -- if you care to write an answer, I'll accept it! – carlosvalderrama Dec 11 '19 at 16:25