Ich arbeite momentan ein einem kleinen Skript, dass ich mir folgende Funktionalität ermöglichen soll (vollständiges Minimalbeispiel: s. unten):
- Ich möchte zunächst eine Umgebung (Tabelle) newlist definieren, in der ein <key> bzw. eine Option über pgfkeys eingegeben werden kann. Der <value> des keys soll im Befehl \optionstatus festgehalten werden (mögliche Werte: on / off).
Die eingegebene Option soll nun in den Einträgen der Umgebung weiterverarbeitet werden. Hierbei soll für jeden Eintrag \entry ein counter erzeugt und auf 1 gesetzt werden, wenn der <key> auf on eingestellt ist (\optionstatus = on).
\pgfkeys{% /newlist/.is family, /newlist, default/.style = {% option = default}, option/.style = {optionlist/#1/.get = \optionstatus}, optionlist/.cd, true/.initial = on, false/.initial = off, on/.initial = on, default/.initial = off, off/.initial = off, expand/.initial = on, no expand/.initial = off, } \newenvironment{newlist}[1][]{% \pgfkeys{/newlist, default, #1}% \begin{longtable}{l | l}}{\end{longtable}}
Im Textteil (außerhalb der Umgebung) soll dann ein Befehl ausgeführt werden, der nun wiederum den counter weiter verarbeitet. Die Standardausgabe des Befehls soll hierbei B sein.\newcommand{\entry}[1]{#1 & \makeatletter \ifstrequal{on}{\optionstatus}{environment option is \textbf{on}% \newcounter{#1}\setcounter{#1}{1}}% {environment option is \textbf{off}} \makeatother \\[0.5cm]}
Ist nun\newcommand{\textcommand}{% \makeatletter \ifstrequal{on}{\optionstatus}{% if \optionstatus = on \ifstrequal{1}{\value{#1}}{% command \textbf{A} will be executed \textsl{(only one time)}}% if value{command} = 1 {command \textbf{B} will be executed \textsl{(command A was already used)}}\stepcounter{command}}% if value{command} > 1 {command \textbf{B} will be executed \textsl{(command option of newlist was never switched on)}}% if \optionstatus = off \makeatother }
1. die Option \optionstatus = on, so soll- a) wenn der counter = 1 ist, eine Alternative A ausgegeben werden bzw. ein dementsprechender Formatierungsbefehl ausgeführt werden (counter wird erhöht).
b) wenn der counter > 1 ist, die Standardausgabe B verwendet werden.
- a) wenn der counter = 1 ist, eine Alternative A ausgegeben werden bzw. ein dementsprechender Formatierungsbefehl ausgeführt werden (counter wird erhöht).
\documentclass{scrartcl} \usepackage{etoolbox} \usepackage{longtable} \usepackage{pgfkeys} \pgfkeys{% /newlist/.is family, /newlist, default/.style = {% option = default}, option/.style = {optionlist/#1/.get = \optionstatus}, optionlist/.cd, true/.initial = on, false/.initial = off, on/.initial = on, default/.initial = off, off/.initial = off, expand/.initial = on, no expand/.initial = off, } \newenvironment{newlist}[1][]{% \pgfkeys{/newlist, default, #1}% \begin{longtable}{l | l}}{\end{longtable}} \newcommand{\entry}[1]{#1 & \makeatletter \ifstrequal{on}{\optionstatus}{environment option is \textbf{on}% \newcounter{#1}\setcounter{#1}{1}}% {environment option is \textbf{off}} \makeatother \\[0.5cm]} \newcommand{\textcommand}[1]{% \makeatletter \ifstrequal{on}{\optionstatus}{% if \optionstatus = on \ifstrequal{1}{\value{#1}}{% command \textbf{A} will be executed \textsl{(only one time)}}% if value{#1} = 1 {command \textbf{B} will be executed \textsl{(command A was already used)}}\stepcounter{command}}% if value{#1} > 1 {command \textbf{B} will be executed \textsl{(environment option of newlist was never switched on)}}% if \optionstatus = off \makeatother } \begin{document} \noindent\textbf{table (newlist) with entries and option (switched on):} \begin{newlist}[option = on] \entry{firstentry} test & the true value of the environment option is \textbf{\optionstatus}\\ \end{newlist} \noindent\textbf{text with commands:}\\[0.25cm] textcommand: \textcommand{firstentry}\\[0.5cm] textcommand: \textcommand{firstentry}\\[0.25cm] \centering \small\textsl{$\rightarrow$ output of textcommand depends on how often the "textcommand" is used}\\[1cm] \raggedright\noindent\textbf{what I expected:}\\[0.5cm] "command \textbf{A} will be executed \textsl{(only one time)}"\\[0.5cm] "command \textbf{B} will be executed \textsl{(command A was already used)}"\\[0.5cm] \end{document}
Der Wert "on" scheint auf jeden Fall ordnungsgemäß in die Option \optionstatus übergeben geworden zu sein (die Probe mit der Eingabe des Befehls \optionstatus gibt zumindest das Richtige aus).
Einen schönen Tag!