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

verbatimEnvironments can't take more than one Regex #435

Closed MoritzBeroRoos closed 1 year ago

MoritzBeroRoos commented 1 year ago

Hi, i am trying to use latexindent with pythontex which is why i am trying to treat all Environments starting with 'py' or with 'jl' as verbatim. My testing latex is:

\begin{document}

a
\begin{latexcode}
import pygments
print(r'\begin{center}')
print(r'\textit{A message 2 from Python!}')
print(r'\end{center}')
\end{latexcode}
\end{document}

My defaultSettings.yaml contains:

verbatimEnvironments:
    verbatim: 1
    lstlisting: 1
    minted: 1
    nameAsRegex:
      name: '\w+code\*?'
      lookForThis: 1
    nameAsRegex:
      name: 'py\w*'
      lookForThis: 1
    nameAsRegex:
      name: 'jl\w*'
      lookForThis: 1

But it looks as if latexindent will only treat the last regex-entry in verbatimEnvironments as verbatim. In the above config my code will be indented. If i swap the entrys for py and jl then my code is not indented. Aditionally the lookForThis argument doesnt seem to influence this behaviour (if jl is the last entry it will indent my above code, no matter what lookForThis is set to) Edit: using name: '(py\w*)|(jl\w*)' does very weird things to my code

cmhughes commented 1 year ago

Please use the issue template and I'll try to help.

cmhughes commented 1 year ago

I can't be sure what you're trying to do, but perhaps the following

name: '(?:py|jl)\w*'
MoritzBeroRoos commented 1 year ago

your suggested regex does solve this specific problem, thank you. But i do not see why my original solution doesn't work. That's why i openend an Issue (now with template over here [https://github.com/cmhughes/latexindent.pl/issues/436])