2

I've created for my lessonbooks a boolean studentversion who can hide or reveal some teacher stuff under the advice of CarLatex. (see topic : https://tex.stackexchange.com/a/478695/169294)

Is it possible to link a key-word for true/false statement ? In my mind, I wish to have the boolean : 'version' who can be set to 'student'(true) or 'teacher'(false). So that I can write : \setbool{version}{teacher} rather than \setbool{studentversion}{false}.

A MWE will be :

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{etoolbox}


%%Current behaviour
\newbool{studentversion}
\setbool{studentversion}{false}

%%Desired behaviour
%\newbool{version}
%\setbool{version}{teacher}

\begin{document}

    \ifbool{studentversion}%
        {The studentversion boolean is set to true}%
        {The studentversion boolean is set to false}
\end{document}

Guess it's a detail but i'm sure it can help me to make my documents clearer for later use.

2
  • 1
    If you want to have multiple "audiences" there is also the multiaudience package that comes in handy.
    – TeXnician
    Jun 8, 2019 at 18:27
  • @TeXnician I did not know that package. After i read the manual, seems it could be usefull. But i've already build my commands on the boolean. A simple \ifbool is sufficient to hide answers in a table at the moment. I keep in mind it for future improvements.
    – Piroooh
    Jun 9, 2019 at 8:25

1 Answer 1

2

Here's a suggestion with an alternative syntax. We define a new command \setversion which takes either student or teacher as a parameter and sets the boolean value studentversion accordingly. For any other parameter an error is reported.

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{etoolbox}

%%Current behaviour
\newbool{studentversion}
\setbool{studentversion}{false}

%%Desired behaviour
%\newbool{version}
%\setbool{version}{teacher}

\newcommand\setversion[1]{%
    \def\tempa{#1}%
    \def\tempb{student}%
    \ifx\tempa\tempb
        \setbool{studentversion}{true}%
    \else
        \def\tempb{teacher}%
        \ifx\tempa\tempb
            \setbool{studentversion}{false}%
        \else
            \errmessage{Unknown value for studentversion: #1}%
        \fi
    \fi
}

\begin{document}

    \setversion{student}%
    \ifbool{studentversion}%
        {The studentversion boolean is set to true}%
        {The studentversion boolean is set to false}

    \setversion{teacher}%
    \ifbool{studentversion}%
        {The studentversion boolean is set to true}%
        {The studentversion boolean is set to false}

    % \setversion{other}%
\end{document}

outputs

enter image description here

1
  • 1
    I was so obsessed to redefine tags (T/F) that i forgot to define a command who can set it. Pretty nice answer ! I like the \errmessage{} case. Thank you !
    – Piroooh
    Jun 8, 2019 at 13:23

You must log in to answer this question.

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