Etoolbox 包:示例

Etoolbox 包:示例

如何替换类似C的代码?

\documentclass{book}

% C-like code : #define FinalCompilationBooleanIsOn 1
% C-like code : if FinalCompilationBooleanIsOn {

    \usepackage{pst-all}
    \usepackage[crop=off]{auto-pst-pdf}

% C-like code : }

\begin{document} 

% C-like code : if FinalCompilationBooleanIsOn {

    \begin{pspicture}
    \psframe*[linecolor=blue](10,10)
    \end{pspicture}

% C-like code : }

\end{document}

答案1

像这样 :

\documentclass{book}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% usepackages %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{etoolbox}

\newbool{FinalCompilation}

\boolfalse{FinalCompilation}
%\booltrue{FinalCompilation} % uncomment if needed

\ifbool{FinalCompilation}{ % fork for packages, before document

    \usepackage{pst-all}
    \usepackage[crop=off]{auto-pst-pdf}

}{} % the 'else' is left empty here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% end of usepackages %%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% beginning of the document %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document} 

\ifbool{FinalCompilation}{ % fork inside the document, same syntax

        \begin{pspicture}
        \psframe*[linecolor=blue](10,10)
        \end{pspicture}

}{Normal text : graphic not included.} % the 'else' is used here

\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% end of the document %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

相关内容