编译两个版本的文档

编译两个版本的文档

我正在尝试从同一源代码创建两个不同版本的文档。其中一个版本应排除文档的机密部分,而另一个版本应保留机密部分。

我的想法是标记包通过简单地添加或省略标签来创建两个不同的版本\usetag{关闭}。当我省略标签时,我会收到底部包含的错误消息。

我需要在环境或命令中使用它,因为我在文档中多次使用此功能。

示例

\documentclass{article}

%%%%% Other packeges used in project %%%%%
\usepackage[english]{babel} % danske overskrifter
\usepackage[utf8]{inputenc} % Skal passe til editorens indstillinger
\usepackage[sfdefault]{roboto}
\usepackage[T1]{fontenc} % fonte (output)
\usepackage{lmodern} % vektor fonte
\usepackage{graphicx} % indsættelse af billeder
\usepackage{epstopdf} %Tilfj "--enable-write18" i argumentet for LaTex build. Dette vil konvertere .eps figurer til pdf-format
\usepackage{subfigure}
\usepackage{a4wide}
\usepackage{hhline}
\usepackage{xcolor}
\usepackage{lastpage}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue}
\usepackage{forloop}
\usepackage{eso-pic}% http://ctan.org/pkg/eso-pic
\usepackage{longtable}
\usepackage{float}
\usepackage{enumitem}

%%%%% Packege Which I'm trying to implement %%%%%
\usepackage{tagging}

%%%%% Blind Text %%%%%
\usepackage{blindtext}

%%%%% Code %%%%%
%\usetag{closed}

\newenvironment{myenvironment}
{
    \color{gray}
    \begin{taggedblock}{closed}
}
{ 
    \end{taggedblock}
}


\begin{document}

\section{This is public}
\blindtext

\begin{myenvironment}
\section{This is Confidential}
\blindtext
\end{myenvironment}

\section{This is public again}
\blindtext

\end{document}

错误消息

Runaway argument?

! File ended while scanning use of \next.
<inserted text> 
                \par 
<*> main.tex

I suspect you have forgotten a `}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type `E' or `X' now and fix your file.

 main.tex



Emergency stop.

<*> main.tex

*** (job aborted, no legal \end found)


Here is how much of TeX's memory you used:
 8935 strings out of 492164
 135695 string characters out of 6125314
 242536 words of memory out of 5000000
 13108 multiletter control sequences out of 15000+600000
 18746 words of font info for 18 fonts, out of 8000000 for 9000
 1141 hyphenation exceptions out of 8191
 39i,0n,40p,886b,321s stack positions out of 5000i,500n,10000p,200000b,80000s
!  ==> Fatal error occurred, no output PDF file produced!

答案1

我认为您尝试创建的包已经存在:multiaudience

利用此包,您可以为不同的受众生成同一文档的不同版本。

在下面的例子中,我定义了两个“受众”:“公众”和“机密”。

\SetNewAudience{public}
\SetNewAudience{confidential}

我投入

\begin{shownto}{confidential}
...
\end{shownto}

什么应该保密。

然后我设置我想要的受众(你也可以在外部进行设置,当你编译文档时,请参阅包装文档)。

例如,以下代码:

\documentclass{article}
%%%%% Other packages used in project %%%%%
\usepackage[english]{babel} % danske overskrifter
\usepackage[utf8]{inputenc} % Skal passe til editorens indstillinger
\usepackage[sfdefault]{roboto}
\usepackage[T1]{fontenc} % fonte (output)
\usepackage{lmodern} % vektor fonte
\usepackage{graphicx} % indsættelse af billeder
\usepackage{epstopdf} %Tilfj "--enable-write18" i argumentet for LaTex build. Dette vil konvertere .eps figurer til pdf-format
\usepackage{subfigure}
\usepackage{a4wide}
\usepackage{hhline}
\usepackage{xcolor}
\usepackage{lastpage}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue}
\usepackage{forloop}
\usepackage{eso-pic}% http://ctan.org/pkg/eso-pic
\usepackage{longtable}
\usepackage{float}
\usepackage{enumitem}

\usepackage{multiaudience}
\SetNewAudience{public}
\SetNewAudience{confidential}

%%%%% Blind Text %%%%%
\usepackage{blindtext}

\begin{document}
\DefCurrentAudience{public}

\section{This is public}
\blindtext

\begin{shownto}{confidential}
\section{This is Confidential}
\blindtext
\end{shownto}

\section{This is public again}
\blindtext

\end{document}

产生以下输出:

在此处输入图片描述

而此代码(唯一的区别是 \DefCurrentAudience{confidential}):

\documentclass{article}
%%%%% Other packages used in project %%%%%
\usepackage[english]{babel} % danske overskrifter
\usepackage[utf8]{inputenc} % Skal passe til editorens indstillinger
\usepackage[sfdefault]{roboto}
\usepackage[T1]{fontenc} % fonte (output)
\usepackage{lmodern} % vektor fonte
\usepackage{graphicx} % indsættelse af billeder
\usepackage{epstopdf} %Tilfj "--enable-write18" i argumentet for LaTex build. Dette vil konvertere .eps figurer til pdf-format
\usepackage{subfigure}
\usepackage{a4wide}
\usepackage{hhline}
\usepackage{xcolor}
\usepackage{lastpage}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue}
\usepackage{forloop}
\usepackage{eso-pic}% http://ctan.org/pkg/eso-pic
\usepackage{longtable}
\usepackage{float}
\usepackage{enumitem}

\usepackage{multiaudience}
\SetNewAudience{public}
\SetNewAudience{confidential}

%%%%% Blind Text %%%%%
\usepackage{blindtext}

\begin{document}
\DefCurrentAudience{confidential}

\section{This is public}
\blindtext

\begin{shownto}{confidential}
\section{This is Confidential}
\blindtext
\end{shownto}

\section{This is public again}
\blindtext

\end{document}

产生以下输出:

在此处输入图片描述

相关内容