TeX - LaTeX Asked on July 12, 2021
I have a big bunch of old to new LaTeX documents written by several independent people. I have to bring them up to date, modern and consistent, standardized LaTeX code. In these documents there are a lot of common “mistakes” or quirks. For example:
begin{equation}
a = b
nonumber
end{equation}
instead of just
[
a = b
]
and similar cases (eqnarray
instead of align
and so on). Or completly random code linebreaks in text (no output changing breaks, like paragraphs) that could be joined.
What tools are recommended to automate such kind of tasks? Mainly to change code snippets to other code snippets without changing the raw content of the snippet. A find-and-replace that takes care of LaTeX syntax/semantic, so to speak.
Are there such tools? I’m working on Windows.
The first step could be loading the nag
package at the beginning of each document, which checks for common mistakes, outdated packages and obsolete commands:
RequirePackage[l2tabu, orthodox]{nag}
Context aware checks and replacements could be made with regular expressions and tools like perl, php, or sed, for example. But you need to know what to look for.
Furthermore helpful: grep, egrep, find, for example:
find "." -name "*.tex" | xargs grep eqnarray
You could extend this to search whole directory trees for a list of undesired patterns.
I would do this on Linux, as there are all mentioned tools usually preinstalled. On Windows, you could install Cygwin (for shell and tools) and ActiveState Perl, for example.
Correct answer by Stefan Kottwitz on July 12, 2021
I'd be tempted to look at this task using regular expressions, which you can access using a variety of tools such as perl
, python
and many more.
latexindent.pl has dedicated replacement switches that can assist with this. If you start with the following file, say myfile.tex
this one has no number
begin{equation}
a = b
nonumber
end{equation}
this one keeps it number
begin{equation}
a = b
end{equation}
and employ the following settings in, say, equation.yaml
replacements:
-
substitution: |-
s/(begin{equation})(.*?)(end{equation})/
my $begin = $1;
my $body = $2;
my $end = $3;
if($body=~m|nonumber|s){
$body =~ s|nonumber(h*R)?||sg;
$begin = "[";
$end = "]";
}
$begin.$body.$end;/sxge
We call latexindent.pl
using
latexindent.pl -rr myfile.tex -l equation.yaml
produces the following output
this one has no number
[
a = b
]
this one keeps it number
begin{equation}
a = b
end{equation}
You'll find further examples and demonstrations in the latexindent.pl documentation and in various answers on this site:
Answered by cmhughes on July 12, 2021
I think you could use blacktex on the lines of black formatter for python by Nico Schlömer. From the documentation
blacktex is a little tool, helping with the article editing for LaTeX. It removes all comments from a given file and corrects some common anti-patterns. For example, with
blacktex in.tex out.tex
the input file
Because of $$a+b=c$$ ({it Pythogoras}),
% @johnny remember to insert name
and $y=2^ng$ with $n=1,...,10$, we have ${Gamma over 2}=8.$
is converted to
Because of
[
a+b = c
]
(textit{Pythogoras}),
and (y = 2^n g) with (n = 1,dots,10), we have (frac{Gamma}{2} = 8).
You can use
blacktex -i in.tex
Answered by Tejas Shetty on July 12, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP