I'm using simple y/n macros as flags in my document to include or exclude certain parts of the overall document (these normally are in a separate "config.tex" file for ease of use). With the forest package, I get strange results when using this approach (using pdftex). The inserted texts seem to be interpreted as text instead of added or non-added leaves.
What am I doing wrong? Thanks in advance for your help.
Minimum working example:
\documentclass[]{scrreprt}
\usepackage{ifthen}
\usepackage[edges]{forest}
\newcommand{\AddIf}[3]{\ifthenelse{\equal{#1}{y}}{#2}{#3}}
\newcommand{\hasOptionOne}{y}
\newcommand{\hasOptionFour}{y}
\begin{document}
The user has the following options:
\begin{itemize}
\AddIf{\hasOptionOne}{\item Option One}{}
\item Option Two
\item Option Three
\AddIf{\hasOptionFour}{\item Option Four}{}
\end{itemize}
\begin{figure}
\centering
\caption{Available Options}
\label{fig-available-options}
\begin{forest}
for tree={draw,align=center},
forked edges,
[Main item
\AddIf{\hasOptionOne}{[Option One]}{}
[Option Two]
[Option Three]
\AddIf{\hasOptionFour}{[Option Four]}{}
]
\end{forest}
\end{figure}
\end{document}
Result:
forest
has a highly sophisticated and powerful parser. I believe it is practically hopeless to try to trick it this way, You would have to makes sure thatforest
sees the expanded version of these\AddIf
s, but the way you construct this command, already\edef\temp{\AddIf{\hasOptionOne}{\item Option One}{}}
fails. So I would like to argue that you should resort to pureforest
methods to achieve what you want.ifthen
package because of such issues.)