I have given (it is already typeseted) two very similar projects: A catalog with exercises and solutions and a catalog with only short solutions for the exercises. Because of the use of the package comment both projects only differ by four lines of code (see the MWE) \includecomment{exercise} vs. \excludecomment{exercise}, \includecomment{answer} vs. \excludecomment{answer} and \includecomment{shortQuestions} vs. \excludecomment{shortQuestions}. Both projects have its own main file: solutions.tex for the full catalog and shortSolutions.tex for short solutions only. Both projects sharing one directory exercises with the files for exercises, let say introduction.tex, ... , measurementTechnology.tex, see the MWE. Each exercise file, for example introduction.tex contains with the environment exercise the exercise itself, the short solution with the environment shortAnswer, the full solution with environment answer and short questions for the current topic with the environment shortQuestions, see the MWE.
My task is to create always both documents with only one tex file. So one have to compile only one tex file, let say solutions.tex to get both documents. I found some information here, but I'am doing something wrong, because I receive only one file with the full catalog.
See my MWE: (Attention! It seems there is a conflict between the environment filecontents and the comment package, because of it my code below compiles only if there aren't blank spaces or tabs in front of \begin{comment environment} and \end{comment environment}. Even LaTeX comments with % after \begin{comment environment} and \end{comment environment} aren't allowed, see below.)
\documentclass[a4paper,
10pt,
fleqn,
twoside,
onecolumn,
openright,
english
]{memoir}
\begin{filecontents}{preamble.tex}
\usepackage[T1]{fontenc}
\usepackage[babel = true]{microtype}
\usepackage[
locale = DE,
per-mode = fraction,
product-symbol = \cdot,
product-units = single
]{siunitx}
\usepackage{
amsmath,
amssymb,
babel,
booktabs,
cancel,
chemplants,
comment,
enumitem,
graphicx,
lscape,
lmodern,
mathtools,
nicefrac,
polynom,
stanli,
xurl
}
\usepackage[text]{esdiff}
\usepackage[
nooldvoltagedirection,
european,
cuteinductors
]{circuitikz}
\usepackage[
pdfstartview = FitB,
bookmarksnumbered,
colorlinks
]{hyperref}
\title{Title for solutions}
\author{Author Name}
\end{filecontents}
\input{preamble}
\includecomment{exercise}
\includecomment{shortAnswer}
\includecomment{answer}
\includecomment{shortQuestions}
\begin{filecontents*}{exercises/introduction.tex}
\begin{exercise}
Text of the current exercise.
\end{exercise}
\begin{shortAnswer}
Text of the idea for the solution or the final result.
\end{shortAnswer}
\begin{answer}
Text of the step to step solution of the current exercise.
\end{answer}
\begin{shortQuestions}
\begin{enumerate}
\item Fist short question to the current subject.
\item Second short question to the current subject.
\item\ldots
\end{enumerate}
\end{shortQuestions}
\end{filecontents*}
\begin{filecontents*}{exercises/measurementTechnology.tex}
\begin{exercise}
Text of the current exercise.
\end{exercise}
\begin{shortAnswer}
Text of the idea for the solution or the final result.
\end{shortAnswer}
\begin{answer}
Text of the step to step solution of the current exercise.
\end{answer}
\begin{shortQuestions}
\begin{enumerate}
\item Fist short question to the current subject.
\item Second short question to the current subject.
\item\ldots
\end{enumerate}
\end{shortQuestions}
\end{filecontents*}
\begin{filecontents}{content.tex}
\frontmatter
\maketitle
\thispagestyle{empty}
\cleardoublepage
\mainmatter
\part{Part 1}
\chapter{Title 1}
\input{exercises/introduction}
\cleardoublepage
\part{Part 2}
\chapter{Title 1}
\input{exercises/measurementTechnology}
\end{filecontents}
\begin{filecontents}{shortSolutions.tex}
\documentclass[
a4paper,
10pt,
fleqn,
twoside,
onecolumn,
openright,
english,
ngerman
]{memoir}
\input{preamble}
\title{Title for short solutions}
\excludecomment{exercise}
\includecomment{shortAnswer}
\excludecomment{answer}
\excludecomment{shortQuestions}
\begin{document}
\input{content}
\end{document}
\end{filecontents}
\begin{document}
\input{content}
\immediate\write18{latex --shell-escape shortSolutions.tex}
\end{document}
I use MikTeX with TeXnicCenter to compile with LaTeX -> DviPs -> ps2pdf (I have to use it) and following profile settings:
LaTeX:
Filepath: D:\TeXnicCenter\MiKTeX\texmfs\install\miktex\bin\x64\latex.exe
Arguments: --enable-write18 -interaction=nonstopmode "%wm"
DviPs (PDF):
Filepath: D:\TeXnicCenter\MiKTeX\texmfs\install\miktex\bin\x64\dvips.exe
Arguments: -P pdf -R0 "%bm.dvi"
and Ghostscript (ps2pdf):
Filepath: D:\TeXnicCenter\MiKTeX\texmfs\install\miktex\bin\x64\mgs.exe
Arguments: -sPAPERSIZE=a4 -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="%bm.pdf" -c save pop -f "%bm.ps"
For the line of code \immediate\write18{latex --shell-escape shortSolutions.tex} the logfile says runsystem(latex --shell-escape shortSolutions.tex)...executed..
What am I doing wrong?
Thank you for your help and effort in advance!



\immediate\write18{latex --shell-escape shortSolutions.tex}(next to last line) that isn't happening. Su-47: does the log file say anything about that line? – Teepeemm Jul 18 '23 at 12:22\begin{exercise} ... \end{exercise}, which the comment package talks about. – MS-SPO Jul 18 '23 at 13:54shortSolutions.tex, wouldn't it? So is the idea to have two files but only directly compile one? – cfr Jul 19 '23 at 01:34filecontentsseems like cheating ;-) All the old files will show up afterward. – John Kormylo Jul 19 '23 at 13:41filecontentsonly here onTeX.Stack Exchange, because otherwise I don't have a possibility to use different files like I do on my machine. Therefore my code on my machine doesn't containfilecontentsenvironments. – Su-47 Jul 21 '23 at 11:50\immediate\write18{latex --enable-write18 shortSolutions.tex}says againrunsystem(latex --enable-write18 shortSolutions.tex)...executed., but I'am receive only the full catalog as before. – Su-47 Jul 22 '23 at 14:29shortSolutions.texonly needs to have\documentclass{article} \begin{document} success \end{document}, and your main document can just have the\immediate\write18. And do you need to have--enable-write18? – Teepeemm Jul 22 '23 at 15:01\immediate\write18command with global paths and separate it into three parts forLaTeX,DviPs(PDF) andGhostscript(ps2pdf) I get the desired result, see also my next comment. Now it would be great to do it without global paths. On the other hand if I think that my editor uses global paths to, then it is perhaps necessary. Any ideas? About--enable-write18I'am not sure, because I got the project with this flags. It is probably not needed. I have to test it. – Su-47 Jul 22 '23 at 16:01LaTeX:\immediate\write18{D:/TeXnicCenter/MiKTeX/texmfs/install/miktex/bin/x64/latex.exe --enable-write18 shortSolutions.tex}, 2.DviPs(PDF):\immediate\write18{D:/TeXnicCenter/MiKTeX/texmfs/install/miktex/bin/x64/dvips.exe -P pdf -R0 shortSolutions.dvi}and 3.Ghostscript(ps2pdf):\immediate\write18{D:/TeXnicCenter/MiKTeX/texmfs/install/miktex/bin/x64/mgs.exe -sPAPERSIZE=a4 -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=shortSolutions.pdf -c save pop -f shortSolutions.ps}.