1

How can I use an if conditonal in LaTeX? If the conditon is true I want to execute a code and if not then continue. Sorry for my example code and English. I dont know how to do it.

\documentclass[11pt,a4paper,titlepage,bibliography=totoc,numbers=noenddot,abstract=on,multi,dvipsnames,svgnames,x11names]{scrreprt}
\usepackage{ifthen} %Paket einbinden
\newboolean{persoenlich} %Deklaration einer boolschen Variable
\setboolean{persoenlich}{false} %Zuweisung eines Wertes.

For your information -> Cross-post https://texwelt.de/wissen/fragen/23136/wie-funktioniert-eine-if-abfrage-in-latex

1

2 Answers 2

3

There are different possibilities.

Plain style would be:

\newif\ifMyIfThingy

This defines three macros, \MyIfThingytrue to set it to true, \MyIfThingyfalse to set it to false and \ifMyIfThingy. You can use it the following way:

\ifMyIfThingy
  True
\else
  False
\fi

There are high level implementations in LaTeX like those provided by etoolbox:

\usepackage{etoolbox}
\newbool{MyIfThingy}
\booltrue{MyIfThingy}
\boolfalse{MyIfThingy}
\ifbool{MyIfThingy}{True}{False}

\newtoggle{MyToggleThingy}
\toggletrue{MyToggleThingy}
\togglefalse{MyToggleThingy}
\iftoggle{MyToggleThingy}{True}{False}

The difference between toggles and booleans in etoolbox are that the bools are internally build upon \newif while the toggles are implemented differently and only use one macro per toggle.

Then there are LaTeX3 booleans like:

\usepackage{expl3}

\ExplSyntaxOn
\bool_new:N \l_my_bool_thingy_bool
\bool_set_true:N \l_my_bool_thingy_bool
\bool_set_false:N \l_my_bool_thingy_bool

\bool_if:NTF \l_my_bool_thingy_bool
  { True }
  { False }
\ExplSyntaxOff

But you should only use LaTeX3 booleans if you code in expl3...

1

With ifthen, you do

\ifthenelse{\boolean{persoenlich}}{True}{False}

Replace True with the code you want to execute if the boolean returns true and similarly for False.

You must log in to answer this question.

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