Anhang / Appendix

Einführung in LaTeX / Introduction into LaTeX

A 1/2

Using \dimexpr and \numexpr for a modulo function

\documentclass[border=5mm]{standalone}
\makeatletter
\def\IsFourMultiple#1{% 
  \ifdim\dimexpr#1pt/4=\numexpr#1/4pt
    \expandafter\@firstoftwo 
  \else
    \expandafter\@secondoftwo
  \fi}
\makeatother
\begin{document} 
\IsFourMultiple{4}{true}{false}
\IsFourMultiple{32}{true}{false}
\IsFourMultiple{15}{true}{false}
\end{document}

Das gleiche Problem mit lualatex:

% !TEX lualatex
\documentclass[border=5mm]{standalone}
\def\IsFourMultiple#1#2#3{% 
  \directlua{if #1//4 == #1/4 then tex.print("#2") else tex.print("#3") end }}
\begin{document} 
\IsFourMultiple{4}{true}{false}
\IsFourMultiple{32}{true}{false}
\IsFourMultiple{15}{true}{false}
\end{document}

A 4.1

Defining a mcaro like \foo[optional]{bla}[optional]{blahblah}

\documentclass[a5paper,12pt]{article}
\makeatletter
\newcommand\optI{}
\newcommand\parI{}
\newcommand\foo[1][]{%
  \begingroup
  \renewcommand\optI{#1}\foo@i}
\newcommand\foo@i[1]{%
  \renewcommand\parI{#1}\foo@ii}
\newcommand\foo@ii[2][]{%
  Parameter: 
  \if\relax\optI\relax Leer\else\optI\fi,
  \if\relax\parI\relax Leer\else\parI\fi,
  \if\relax#1\relax Leer\else#1\fi,
  \if\relax#2\relax Leer\else#2\fi%
  \endgroup}
\makeatother
\begin{document}
\foo{par1}{par2}\par
\foo[opt1]{par1}{par2}\par
\foo{par1}[opt2]{par2}\par
\foo[opt1]{par1}[opt2]{par2}
\end{document}

Zurück zur Hauptseite/Back to main page
Copyright $Id: appendix.html 2 2022-12-28 16:38:18Z voss $