从相同的乳胶源编译文档的两个版本 [英] Compile two versions of a document from the same latex source

查看:71
本文介绍了从相同的乳胶源编译文档的两个版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何自动编译同一文档的两个版本,例如对学生没有答案的版本和对我自己有答案的另一个版本?

How to automatically compile two versions of the same document, for example version without answers for the students and another version with answers for myself?

推荐答案

有几个软件包可以有条件地排除文档的某些部分,例如exercise软件包.

There are several packages that allow to conditionally exclude certain parts of the document, for example the exercise package.

使用TeXstudio,以下魔术注释可用于自动一次编译两个版本(包括针对交叉引用,书目,索引等的重复编译):

With TeXstudio, the following magic comment can be used to automatically compile both versions at once (including repeated compilation for cross-references, bibliographies, indices etc.):

% !TeX program = latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=% -pretex="\newcommand{\version}{noanswer}" -usepretex % | latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=%_solution -pretex="\newcommand{\version}{}" -usepretex % | txs:///view-pdf "?am)_solution.pdf"

\documentclass{article}

% setting a default value in case it is compiled without the magic comment
\ifdefined\version
\else
\def\version{noanswer}
\fi

\usepackage[\version]{exercise}

\begin{document}

    \begin{Exercise}[title={Title},label=ex1]

        question text

    \end{Exercise}

    \begin{Answer}[ref={ex1}]

        solution

    \end{Answer}

\end{document}

这篇关于从相同的乳胶源编译文档的两个版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆