3

I'm in charge of maintaining my company's user manuals for our various products, and I'd like to start using LaTex. Lots of the content between the different manuals is the same, so I'd like to be able to tag which document ID I'm generating, so text for a different document ID wouldn't end up being shown. I've settled on using the etoolbox package, with each possible document number toggled, and just setting \toggletrue for the document ID I'm generating. Then I can use \ifboolexpr with or, which is necessary because lots of things can be shared among different document IDs.

Example 1

The method I've settled on works fine for blocks of text (you can see that \widthB is displayed from line 17 in my 1st example no problem). And setting a length from a command works fine, as in example 1. But when I want to define a parameter based on document ID, and feed that parameter to a command, it won't work. You can confirm this by modifying Example 1 so line 21 uses \widthB instead of \widthA.

\documentclass{minimal}

\usepackage{etoolbox}
\newtoggle{Doc1A}
\newtoggle{Doc2A}
\newtoggle{Doc1B}
\newtoggle{Doc2B}
\toggletrue{Doc1A}


\begin{document}

\newcommand{\widthA}{2in}
widthA \widthA

\newcommand{\widthB}{\ifboolexpr{ togl {Doc1A} or togl {Doc1B} }{3.3in}{4.3in}}
widthB \widthB


\newdimen\mylength
\setlength{\mylength}{\widthA}
mylength \the\mylength

\framebox[\mylength]{example text}

\end{document}

Example 2

This example shows that it is indeed possible to use conditionals, but I find this method to be extremely clunky and inefficient, and I really don't think it will work for this project.

\documentclass{minimal}

\newif\ifDocOneA
\newif\ifDocTwoA
\newif\ifDocOneB
\newif\ifDocTwoB

\DocOneAtrue
\DocTwoAfalse
\DocOneBfalse
\DocTwoBfalse


\begin{document}

\newcommand{\widthC}{\ifnum
    \ifDocOneA 1
    \else
        \ifDocOneB 1
        \else 0
        \fi
    \fi
>0
3.3in
\else
4.3in
\fi}
widthC \widthC

\newdimen\mylength
\setlength{\mylength}{\widthC}
mylength \the\mylength

\framebox[\mylength]{example text}

\end{document}

Any ideas why the conditional in example 1 will not work?

2

You have to use the “expandable” version of \ifboolexpr, that is, \ifboolexpe. I used different lengths so to see more clearly that the desired one is selected.

\documentclass{article}

\usepackage{etoolbox}
\newtoggle{Doc1A}
\newtoggle{Doc2A}
\newtoggle{Doc1B}
\newtoggle{Doc2B}
\toggletrue{Doc1A}


\begin{document}

\newcommand{\widthA}{100pt}
widthA \widthA

\newcommand{\widthB}{\ifboolexpe{ togl {Doc1A} or togl {Doc1B} }{200pt}{300pt}}
widthB \widthB


\newdimen\mylength
\setlength{\mylength}{\widthB}
mylength \the\mylength

\framebox[\mylength]{example text}

\end{document}

enter image description here

  • Wow thank you! I thought it had something to do with expansion, but no matter where I put \expandafter it didn't matter. Thank you again! – James Jun 13 '17 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.