6

So, I wanna have two versions of a document in LaTeX where one versions has additional information - for example by declaring:

\section(important){Formula}
importantFormulaXYZ
\subsection(notimportant){additional Info}
some information about why this formula is important

Then I would like to be able to set a variable in the beginning of the document to true or false where true prints all sections and subsections and false prints only the sections I marked as important.

I don't really know how something like this would be possible so that I can easily switch between getting the document

Formula
importantFormulaXYZ

and the document

Formula
importantFormulaXYZ
additional Info
some information about why this formula is important

Would be great if someone could help me out :) I found some examsheet package that seems to do something similar but it extends way beyond what I need so I hope there is a simpler way to do it :)

Addendum

I would prefer to be able to set the information about when to print it directly at the subsection (as in the example as 'important' and 'not important' for example) and not have something at the beginning of the document that says "print section 1,2,3,7,8 etc." because the more sections I get the more confusing that would get I think and also harder to manage changing the status of sections etc...

4

As I understand your question seems to be about the interface. Ideally you want to mark what should be included on the sectioning level. Unfortunately, this is not really possible in LaTeX as the end of a section or subsection etc. is not explicitly denoted - which means that LaTeX simply does not keep track of when a section ends unless you tell it to do so (for instance by converting them into environments on the user interface level, which isn't a good idea anyways).

The usual ways to accomplish what you want are to simply declare a new switch by \newif\ifonlyimportant and then wrap the additional parts inside that conditional:

\section{Formula}
importantFormulaXYZ

\ifonlyimportant
  \subsection{additional Info}
  some information about why this formula is important
\fi

At the beginning of the document you could call \onlyimportanttrue if the additional parts should be left out and \onlyimportantfalse otherwise.

I think in terms of the interface it is more convinient do this via an environment (even if the difference is minimal). The usual way to do this is the comment package:

\documentclass{article}
\usepackage{comment}

%\includecomment{comment}

\begin{document}
\section{Formula}
importantFormulaXYZ

\begin{comment}
  \subsection{additional Info}
  some information about why this formula is important
\end{comment}
\end{document}

If you want to be independent from a package you could use the following light weight version of this mechanism.

\documentclass{article}
\usepackage{environ}

\makeatletter
\newif\if@nlyimportant
\newtoks\@dditionalinf@
\NewEnviron{additionalinfo}{%
  \global\@dditionalinf@=\expandafter{\BODY}
  \if@nlyimportant\else\the\@dditionalinf@\@dditionalinf@{}\fi}
\let\hideadditional\@nlyimportanttrue
\let\printadditional\@nlyimportantfalse
\makeatother

\hideadditional
%\printadditional

\begin{document}
\section{Formula}
importantFormulaXYZ

\begin{additionalinfo}
  \subsection{additional Info}
  some information about why this formula is important
\end{additionalinfo}
\end{document}
| improve this answer | |

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.