我给出了(已经排版)两个非常相似的项目:一个包含练习和解决方案的目录和一个包含仅有的练习的简答。由于使用了软件包,comment
两个项目只有四行代码不同(参见 MWE)\includecomment{exercise}
vs. \excludecomment{exercise}
、\includecomment{answer}
vs.\excludecomment{answer}
和\includecomment{shortQuestions}
vs. \excludecomment{shortQuestions}
。两个项目都有自己的主文件:仅solutions.tex
用于完整目录和shortSolutions.tex
简答。两个项目共享一个exercises
包含练习文件的目录,例如introduction.tex
、... 、measurementTechnology.tex
,参见 MWE。例如,每个练习文件都introduction.tex
包含环境exercise
练习本身、环境简答shortAnswer
、环境完整解决方案answer
和环境当前主题的简答问题shortQuestions
,参见 MWE。
我的任务是创造总是两个文档只有一个tex
文件。因此,只需编译一个tex
文件,比如说solutions.tex
可以获取两个文档。我找到了一些信息这里,但我做错了,因为我只收到一个包含完整目录的文件。
参见我的 MWE: (注意力!似乎环境filecontents
和包之间存在冲突,因此只有当和comment
前面没有空格或制表符时,下面的代码才会编译。甚至 和之后的LaTeX 注释也是不允许的,见下文。)\begin{comment environment}
\end{comment environment}
%
\begin{comment environment}
\end{comment environment}
\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}
我使用MikTeX
withTeXnicCenter
进行编译LaTeX -> DviPs -> ps2pdf
(我必须使用它)并遵循以下配置文件设置:
LaTeX
:
文件路径:D:\TeXnicCenter\MiKTeX\texmfs\install\miktex\bin\x64\latex.exe
参数:--enable-write18 -interaction=nonstopmode "%wm"
DviPs
(PDF):
文件路径:D:\TeXnicCenter\MiKTeX\texmfs\install\miktex\bin\x64\dvips.exe
参数:-P pdf -R0 "%bm.dvi"
和Ghostscript
(ps2pdf
):
文件路径:D:\TeXnicCenter\MiKTeX\texmfs\install\miktex\bin\x64\mgs.exe
参数:-sPAPERSIZE=a4 -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="%bm.pdf" -c save pop -f "%bm.ps"
对于代码行 \immediate\write18{latex --shell-escape shortSolutions.tex}
日志文件说runsystem(latex --shell-escape shortSolutions.tex)...executed.
。
我究竟做错了什么?
提前感谢您的帮助和努力!