Beim Lesen einer Datei csv
aktualisiert das LaTeX-Paket csvsimple
den Wert einer Variablen, z. B. \location
, und identifiziert eine bestimmte Spalte.LaTeX: Bedingte Ausführung der Anweisung bei Änderung einer Variablen
Ich möchte, dass der Wert \location
im Text angezeigt wird, nur wenn sein Wert sich tatsächlich ändert.
Das folgende Stück Code funktioniert nicht.
\documentclass{article}
\usepackage{csvsimple}
\usepackage{ifthen}
\begin{document}
\def\oldlocation{}
\csvreader[head to column names,separator=tab]{input.tab}{}{%
\ifthenelse{\equal{\oldlocation}{\location}}{\relax}{%
\begin{center}\location{}\end{center}
\element{}\\
\renewcommand{\oldlocation}{\location}}
}
\end{document}
Probe input.tab
:
location[tab]element
Shelf 1 [tab] Item A
Shelf 1 [tab] Item B
Shelf 1 [tab] Item C
Shelf 1 [tab] Item D
Shelf 1 [tab] Item E
Shelf 2 [tab] Item F
Shelf 2 [tab] Item G
Shelf 2 [tab] Item H
Shelf 2 [tab] Item I
Shelf 2 [tab] Item J
Shelf 3 [tab] Item K
Shelf 3 [tab] Item L
Shelf 3 [tab] Item M
Shelf 3 [tab] Item N
Shelf 3 [tab] Item O
Erwartete Ausgabe:
Shelf 1
Item A
Item B
Item C
Item D
Item E
Shelf 2
Item F
Item G
Item H
Item I
Item J
Shelf 3
Item K
Item L
Item M
Item N
Item O
@Werner: Ja, danke. Bitte, siehe bearbeitete Frage. – ggna