I have a document that I need to manage multiple versions of, for multiple languages. So far I've kept a different LaTeX project for each, but it's a bit annoying to have to open, edit and save multiple projects every time. I want to be able to "label" parts of the document, and have only the corresponding labeled parts show in the PDF file depending on which "version" option is selected.
The text is interspersed through the document, so keeping different tex files and including them conditionally does not work. Would also prefer not to change the document class.
The best option I've found was to declare an environment to surround the blocks of text with a comment declaration, like so:
\usepackage{verbatim}
\newenvironment{v1}{}{} % to show
% \newenvironment{v1}{\comment}{\endcomment} % to hide
(...)
\begin{v1}
(...)
\end{v1}
Well, \comment
and \endcomment
just straight up don't work, even when directly included in the text I get a fatal error from Overleaf. I also tried importing comment
instead of verbatim
, with the same results.
\begin{comment}
and \end{comment}
generally (not always) work when directly included in the text, but also throw a fatal error when used in the environment declaration (as in \newenvironment{v1}{\begin{comment}}{\end{comment}}
).
The errors I get vary depending on what exactly I try to comment out. I always get a LaTeX3 Error: Command '\FA' already defined!
error stemming from one of the template files (it's not being edited), and complaints about runaway arguments or missing }
(which I've checked and don't seem to actually exist).
What would be the correct way to utilize \begin{comment}
and \end{comment}
in the environment declaration? Is there another way to achieve a similar end?
Best Answer
Here's a way to combine parts as you need them using package
codesection
.The basic idea is:
Flags: Here I defined
E
andG
for English or German text parts. You are free to use any number of such flags with names you like. To switch versions, set these flags, and compile afterwords. With two flags you have 4 cases, as mentioned in the comment line. Or use\SetCodeSection
, see the manual.Parts/versions: You use the special environment provided by said package. All you need to do is to enter your flags name. Inside use regular LaTeX commands.
For simplicity I set both flags to true as an example. You see:
Result:
P.S.: Whlie this setting
creates just this from the same code: