Closed torik42 closed 6 months ago
I have a few ideas on how to do this. Hoping to get to this over the weekend.
Here are a couple of options, both give your desired output.
Using the following
replacements:
-
substitution: |-
s/
(.*?)(\\begin\{document.*)/
my $preamble = $1; # store preamble
my $body = $2; # store body
$body =~ s|(?<!\\) \\l?Vert #
\s* (?P<content> .+? ) \s* # make substitutions
(?<!\\) \\r?Vert # on BODY
|\\norm{$+{content}}|sgx; #
$preamble.$body;/esgx # reassemble
and calling
latexindent.pl -l -r myfile.tex
Using
specialBeginEnd:
preamble:
begin: \\documentclass
end: \\begin\{document\}
lookForThis: verbatim
replacements:
-
substitution: |-
s/
(?<!\\) \\l?Vert
\s* (?P<content> .+? ) \s*
(?<!\\) \\r?Vert
/\\norm{$+{content}}/sgx
stores the preamble as a verbatim block and using the rv
switch as in
latexindent.pl -rv -l myfile.tex
Let me know if you need anything else on this.
Sorry for the (very) late reply. For my specific case I just use a negative lookbehind for the \DeclarePairedDelimiter
now. The evaluate modifier still gave me some other ideas (I tried it quite some time ago and couldn’t make it work), now it worked. Thanks.
original .tex code
yaml settings
actual/given output
desired or expected output
anything else
My expectation was that replacements would respect the
indentPreamble
key (also the modifylinebreaks switch respects it). One could have a separate setting to enable replacements in the preamble, if one wants them also there. Or a key to only use latexindent for the preamble. This would allow for different configurations for the preamble and the rest by running latexindent twice.