3

I must print my PDF file often with 2 options: A or B.

When I change contents of file, it's often error-prone when so much positions in document must be changed.

Now I want use dynamic change:

example some text definition:

Definition in Option A:

vartitleA.1 = This is option A

vartitleA.2 = Option A: ABCDE

vartitleA.3 = Display option A

Definition in Option B:

vartitleB.1 = No A, only B

vartitleB.2 = Option B: GHJK1238

vartitleB.3 = Display option B - No A

and in code when I select the option = B, then the .pdf file should display all definition of option B in all positions of vartitle1, 2, 3

My minimal example code:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{colortbl}
%Need definition text of option A & B
% vartitleA.1 = This is option A
% vartitleA.2 = Option A: ABCDE
% vartitleA.3 = Display option A
%...similar for option B

\begin{document}

%here can i set ex. select option = option A and automatic set vartitle1=vartitleA.1, vartitle2 = vartitleA.2, vartitle3 = vartitleA.3...
\begin{tcolorbox}
This is option A %\vartitle1
\tcblower
Option A: ABCDE %\vartitle2
\end{tcolorbox}

\begin{tcolorbox}[title = {Display option A}] %vartitle3 
This is option A %\vartitle1
\tcblower
Option A: ABCDE %\vartitle2
\end{tcolorbox}

Display option A %\vartitle3 

\end{document}

Thanks

  • 2
    Sorry, your question is totally confusing. Which option? There is no option apart from the tcolorbox title. What is the dynamic change? – user31729 Feb 9 '19 at 9:41
  • @ChristianHupfer; thank so much, i just some updated, may be better understanding – latexforti Feb 9 '19 at 9:44
  • 1
    Either I am totally stupid or .... No, it has not been clarified for me... %here can i set ex. select option = option A is not really useful for -- what is option A? How should we test for option A? – user31729 Feb 9 '19 at 9:49
  • Sorry, i don' know how i can definite variable and text display of option A, B. – latexforti Feb 9 '19 at 9:59
4

I defined six macros, 3 each for the \variantA... and \variantB... titles and an \ifoptionA macro, that is toggled with \SelectOption, which an be specified as A or anything else, which corresponds to B then.

The toggling defines \localtitle... which are displayed in the tcolorbox instances.

enter image description here

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{colortbl}
%Need definition text of option A & B
% vartitleA.1 = This is option A
% vartitleA.2 = Option A: ABCDE
% vartitleA.3 = Display option A
%...similar for option B

\newif\ifoptionA

\newcommand{\vartitleAone}{This is option A}
\newcommand{\vartitleAtwo}{option ABCDE}
\newcommand{\vartitleAthree}{Display option A}

\newcommand{\vartitleBone}{No A,only B}
\newcommand{\vartitleBtwo}{option B: GHJK1238}
\newcommand{\vartitleBthree}{Display option B - No A}


\def\localtitleone{}
\def\localtitletwo{}
\def\localtitlethree{}


\newcommand{\SelectOption}[1]{%
  \expandafter\ifstrequal\expandafter{#1}{A}{%
    \global\optionAtrue
  }{%
    \global\optionAfalse
  }%
  \ifoptionA
  \gdef\localtitleone{\vartitleAone}
  \gdef\localtitletwo{\vartitleAtwo}
  \gdef\localtitlethree{\vartitleAthree}
  \else
  \gdef\localtitleone{\vartitleBone}
  \gdef\localtitletwo{\vartitleBtwo}
  \gdef\localtitlethree{\vartitleBthree}
  \fi
}


\newtcolorbox{mynicebox}[1][]{%
  #1%
}


\begin{document}

\SelectOption{A}

\begin{mynicebox}
  \localtitleone
  \tcblower
  \localtitletwo
\end{mynicebox}

\begin{mynicebox}[title={\localtitlethree}]
  \localtitleone
  \tcblower
\localtitletwo
\end{mynicebox}


Display option A %\vartitleA.3 


\SelectOption{B}

\begin{mynicebox}
  \localtitleone
  \tcblower
  \localtitletwo
\end{mynicebox}

\begin{mynicebox}[title={\localtitlethree}]
  \localtitleone
  \tcblower
\localtitletwo
\end{mynicebox}



\end{document}
| improve this answer | |
  • brillant, your above code that i you truly want. Many thank – latexforti Feb 9 '19 at 10:40
  • 3
    +1 for displaying telepathy and divination skills! :-) – Mico Feb 9 '19 at 11:32
  • 1
    @Mico: Yes, I will get a badge for this ;-) – user31729 Feb 9 '19 at 11:40
  • 3
    This site should definitely provide a GOLD badge for such a skill!! 😀😀 – Mico Feb 9 '19 at 12:13
  • 2
    @Mico: Go ahead to Meta.SE and propose such badge times. And of course, for me, it must be a new category: Platinum ;-) – user31729 Feb 9 '19 at 15:02

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.