0

I am facing some - probably very silly - problem. I want a multi-version document - one for me, one for my students and one complete version.

The idea is that you just change the versioning in the beginning of the document and it switches the font's color for the parts I want to leave blank (usually my examples) : on the student version it writes parts of the text in the same color as the background (thus invisible), on teacher's version, it writes in a different color (so that I know what my students have to fulfill) and the complete version writes everything in black. I have a big document and the system works really well.

But I'm just struggling a bit when it comes to handling this system with tikz. The following code :

\documentclass[a4paper,11pt]{article}

\usepackage{tikz}
\usepackage{ifthen}

\def\fondExercice{gray!10}
\def\couleurMaitre{gray!80}
\def\couleurComplet{black}

\newcommand{\versionEleve}{
    \def\macouleur{\fondExercice}
    \def\edition{E}
}
\newcommand{\versionMaitre}{
    \def\macouleur{\couleurMaitre}
    \def\edition{P}
}
\newcommand{\versionComplete}{
    \def\macouleur{\couleurComplet}
    \def\edition{C}
}

\newcommand\couleurTik[1][black]{
    \ifthenelse{\equal{\edition}{E}}{\fondExercice}{#1}
}

\begin{document}
    \versionEleve

    The current color is \couleurTik[yellow]

    \begin{tikzpicture}
        \draw[\couleurTik] (0,0) circle (1);    
    \end{tikzpicture}


\end{document}

doesn't work and produces an error I don't understand : \couleurTik[yellow] produces the expected result but \draw[\couleurTik] (0,0) circle (1); produces the mistake.

I guess it's some kind of expansion problem, but altough I tried to read a bit about that, it remains quite mysterious to me.

Anybody has a clue on why it fails ? Thanks in advance !

EDIT :

After looking for colorlet, I found out that this works

\documentclass[a4paper,11pt]{article}

\usepackage{tikz}
\usepackage{ifthen}

\def\fondExercice{gray!10}
\def\couleurMaitre{gray!80}
\def\couleurComplet{black}

\newcommand{\versionEleve}{
    \def\macouleur{\fondExercice}
    \colorlet{couleurTik}{\fondExercice}
    \def\edition{E}
}
\newcommand{\versionMaitre}{
    \def\macouleur{\couleurMaitre}
    \colorlet{couleurTik}{\couleurMaitre}
    \def\edition{P}
}
\newcommand{\versionComplete}{
    \def\macouleur{\couleurComplet}
    \colorlet{couleurTik}{\couleurComplet}
    \def\edition{C}
}


\begin{document}
    \versionEleve


    \begin{tikzpicture}
        \draw[color=couleurTik] (0,0) circle (1);   
    \end{tikzpicture}


\end{document}

But I still don't get why the first code didn't ...

  • You could just redefine the styles. But I am afraid that some student will just use pdftotext or something like this to find out what you tried to hide. ;-) – marmot Jul 16 '18 at 11:28
  • They just get a printed version of the document, so they cannot do that. But the problem is not there for me, I am quite happy with this system, it's just with tikz that it's not working. – HerculePoivrot Jul 16 '18 at 11:31
  • What I meant is that you may want to define a style couleurTik instead of the macro couleurTik and set it accordingly to white (?) or something visible. – marmot Jul 16 '18 at 11:35
  • Why not using \definecolor and \colorlet? – egreg Jul 16 '18 at 11:37
  • Is it required to use \definecolorhere ? \draw[gray!10]works and my macro produces gray!10, that's the thing I don't understand. – HerculePoivrot Jul 16 '18 at 11:40
1

You can simply define a new tikzstyle for each version using the defined colours.

\documentclass[a4paper,11pt]{article}

\usepackage{tikz}
\usepackage{ifthen}

\def\fondExercice{gray!10}
\def\couleurMaitre{gray!80}
\def\couleurComplet{black}

\newcommand{\versionEleve}{
    \def\macouleur{\fondExercice}
    \def\edition{E}
    \tikzstyle{mycolor} = [\macouleur]
}
\newcommand{\versionMaitre}{
    \def\macouleur{\couleurMaitre}
    \def\edition{P}
    \tikzstyle{mycolor} = [\macouleur]
}
\newcommand{\versionComplete}{
    \def\macouleur{\couleurComplet}
    \def\edition{C}
    \tikzstyle{mycolor} = [\macouleur]
}

\newcommand\couleurTik[1][black]{
    \ifthenelse{\equal{\edition}{E}}{\fondExercice}{#1}
}

\begin{document}
    \versionEleve
    %\versionMaitre
    %\versionComplete

    \begin{tikzpicture}
        \draw[mycolor] (0,0) circle (1);    
    \end{tikzpicture}


\end{document}
  • 1
    \tikzstyle has been deprecated for several years. – egreg Jul 16 '18 at 12:41

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.