1

I want to create multiple versions of the same exercises sheets (teacher, students, solutions, hints,...). So I'm trying to use the "versions" package.

As I have to do it twice a week, I want to minimize the work needed every time, so I'm putting everything that I want to print in a "\shortcut" command, that I call multiple times in different versions settings.

This is what I would expect to work:

\documentclass{article}
\usepackage{versions}

\newenvironment{envA}{}{}
\newenvironment{envB}{}{}


\newcommand{\shortcut}{
\begin{envA}TEXT\end{envA}
\begin{envB}OTHER TEXT\end{envB}
}

\begin{document}

\excludeversion{envB}
\shortcut

\includeversion{envB}
\excludeversion{envA}
\shortcut

\end{document}

But I get various errors, show here (sorry for the picture, but there is a lot of them): enter image description here

The very frustating part is that if I directly type the content where I want to appear, it works and produces the expected result:

\documentclass{article}
\usepackage{versions}

\newenvironment{envA}{}{}
\newenvironment{envB}{}{}


\begin{document}

\excludeversion{envB}
\begin{envA}TEXT\end{envA}
\begin{envB}OTHER TEXT\end{envB}

\excludeversion{envA}
\includeversion{envB}
\begin{envA}TEXT\end{envA}
\begin{envB}OTHER TEXT\end{envB}

\end{document}

Anyone can help ?

2
  • you can't hide the end marker of such version commands in some other command - LaTeX must be able to find them with out expanding macros. Sep 15, 2019 at 14:43
  • Oh, that's good to know. I had assumed the compiler expanded everything before handling the versions (sort of syntax befor semantics). Sep 15, 2019 at 19:43

1 Answer 1

0

I don't know why your setup fails, and I'm not really interested in investigating the reason. Therefore I setup a small replacement. It doesn't use environments but a macro that takes two arguments (\useV), the first argument is a version, the second is the text which should appear if that version is included. Versions are included with \includeV and excluded with \excludeV. Both \includeV and \excludeV accept a comma separated list of versions which should be included or excluded. The version names can contain anything except the tokens {, } and #.

\documentclass{article}

\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \l_juliafatou_included_tl
\tl_set:Nn \l_juliafatou_included_tl { _ }
\NewDocumentCommand \includeV { m }
  {
    \clist_map_inline:nn { #1 }
      {
        \tl_if_in:NnF \l_juliafatou_included_tl { _##1_ }
          { \tl_put_right:Nn \l_juliafatou_included_tl { ##1_ } }
      }
  }
\NewDocumentCommand \excludeV { m }
  {
    \clist_map_inline:nn { #1 }
      {
        \tl_if_in:NnT \l_juliafatou_included_tl { _##1_ }
          { \tl_replace_once:Nnn \l_juliafatou_included_tl { _##1_ } { _ } }
      }
  }
\NewDocumentCommand \useV { m }
  {
    \tl_if_in:NnT \l_juliafatou_included_tl { _#1_ }
  }
\ExplSyntaxOff

\newcommand*\shortcut
  {%
    \useV{A}{Text}%
    \useV{B}{Other text}%
    \useV{C}{Third text}%
  }

\begin{document}

\includeV{A}
\excludeV{B,C}
\shortcut

\includeV{B,C}
\excludeV{A}
\shortcut

\end{document}

Output:

enter image description here

1
  • Thank you, this is exactly what I needed. I've tried it and it performs as I expected my code would. Sep 15, 2019 at 19:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .