Liebe Texwelt, ich habe in meinem Tikzpicture mehrere hundert colorboxen. Für meine Abschlussarbeit wäre es hilfreich, die genaue Anzahl dieser durch einen speziellen Suchbefehl o.ä. zu ermitteln, da man sich bei so großen Zahlen auch leicht mal verzählen kann.

Zusätzlich wäre es notwendig, diesen Zählmechanismus nur auf einen bestimmten Abschnitt zu begrenzen, da ich dieses Tikzpicture in abgeänderter Form noch weitere Male in meinem Dokument verwende und auch sonst colorboxen öfter mal vorkommen.

Hier eine abgespeckte version meines Tikzpictures:

Open in Online-Editor
\documentclass[fleqn,12pt,a4paper,german]{article}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{tikz}

\begin{document}
Auch hier colorboxen wie 
\colorbox{cyan}{00} (diese sollen allerdings nicht gezählt werden)
\\[4ex]
%colorboxen erst ab hier zählen 
{\begin{tikzpicture} 
[
point/.default=5pt 
]   
\foreach[count=\i,evaluate=\i as \angle using (\i)*25.71] \text in  {
    \colorbox {cyan} {0\textcolor{white}1},\colorbox {cyan} {0\textcolor{white}2},\colorbox {cyan} {0\textcolor{white}3},\colorbox {cyan} {0\textcolor{white}4}, \colorbox {cyan} {1\textcolor{white}0},\colorbox {cyan} {1\textcolor{white}1},\colorbox {cyan} {1\textcolor{white}2},\colorbox {cyan} {1\textcolor{white}3},\colorbox {cyan} {2\textcolor{white}0},\colorbox {cyan} {2\textcolor{white}1},\colorbox {cyan} {2\textcolor{white}2},\colorbox {cyan} {3\textcolor{white}0},\colorbox {cyan} {4\textcolor{white}0},\colorbox {cyan} {0\textcolor{white}0}, % Beschriftung der Kreise
}
\node[rotate=\angle, anchor=west] (node\i) at (\angle:0.8) {\text};

[
point/.default=5pt 
]

\foreach[count=\i,evaluate=\i as \angle using (\i)*25.71] \text in  {
    \colorbox {cyan} {0\textcolor{white}1},\colorbox {cyan} {0\textcolor{white}2},\colorbox {cyan} {0\textcolor{white}3},\colorbox {cyan} {0\textcolor{white}4}, \colorbox {cyan} {1\textcolor{white}0},\colorbox {cyan} {1\textcolor{white}1},\colorbox {cyan} {1\textcolor{white}2},\colorbox {cyan} {1\textcolor{white}3},\colorbox {cyan} {2\textcolor{white}0},\colorbox {cyan} {2\textcolor{white}1},\colorbox {cyan} {2\textcolor{white}2},\colorbox {cyan} {3\textcolor{white}0},\colorbox {cyan} {4\textcolor{white}0},\colorbox {cyan} {0\textcolor{white}0}, 
    \colorbox {cyan} {1\textcolor{white}1},\colorbox {cyan} {1\textcolor{white}2},\colorbox {cyan} {1\textcolor{white}3},\colorbox {cyan} {2\textcolor{white}0},\colorbox {cyan} {2\textcolor{white}1},\colorbox {cyan} {2\textcolor{white}2},\colorbox {cyan} {3\textcolor{white}0},\colorbox {cyan} {4\textcolor{white}0},\colorbox {cyan} {0\textcolor{white}0},
    \colorbox {cyan} {1\textcolor{white}1},\colorbox {cyan} {1\textcolor{white}2},\colorbox {cyan} {1\textcolor{white}3},\colorbox {cyan} {2\textcolor{white}0},\colorbox {cyan} {2\textcolor{white}1},\colorbox {cyan} {2\textcolor{white}2},\colorbox {cyan} {3\textcolor{white}0},\colorbox {cyan} {4\textcolor{white}0},\colorbox {cyan} {0\textcolor{white}0}, % Beschriftung der Kreise
}
\node[rotate=\angle, anchor=west] (node\i) at (\angle:1.8) {\text};

\end{tikzpicture}
%bis genau hier 
\end{document}

gefragt 21 Sep '15, 09:35

laa21794's gravatar image

laa21794
29431821
Akzeptiert-Rate: 0%

bearbeitet 07 Feb '16, 11:37

saputello's gravatar image

saputello
11.1k154365

1

Das ist eigentlich eine nach Features von Editor oder speziellen Filtern bzw. Suchbefehlen oder Skriptsprachen und weniger eine (La)TeX-Frage. Ich würde beispielsweise in emacs schlicht die Region selektieren, speichern und dann mit grep und wc oder ein wenig sed-Magie zählen lassen. Man könnte auch mit elisp selbst in der aktuellen Region bestimmte reguläre Ausdrücke oder Strings suchen und zählen lassen. Ich bin aber in elisp nicht so firm.

(21 Sep '15, 11:00) saputello

Unter GNU/Linux pdftotext -f <Seite Beginn> -l <Seite Ende> <Datei.pdf> - | wc -w.

(03 Nov '15, 21:36) Henri

Wenn es wirklich nur darum geht, die \colorbox-Anweisungen zu zählen, dann kann man das tatsächlich LaTeX machen lassen:

Open in Online-Editor
\documentclass[fleqn,12pt,a4paper,german]{article}
\usepackage[utf8]{inputenc}% utf8x nur verwenden, wenn unbedingt notwendig!
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{tikz}

\makeatletter
\newcounter{colorboxnum}
\newcommand*{\saved@colorbox}{}
\newcommand*{\countcolorbox}{%
  \ifx\saved@colorbox\@empty
    \let\saved@colorbox\colorbox
    \renewcommand*{\colorbox}{\stepcounter{colorboxnum}\saved@colorbox}%
  \fi
}
\AtEndDocument{\typeout{Es gab \thecolorboxnum\space relevante
    \string\colorbox\space Anweisungen.}}
\makeatother

\begin{document}
Auch hier colorboxen wie 
\colorbox{cyan}{00} (diese sollen allerdings nicht gezählt werden)
\\[4ex]
%colorboxen erst ab hier zählen 
\begin{tikzpicture} 
[
point/.default=5pt 
]
\countcolorbox
\foreach[count=\i,evaluate=\i as \angle using (\i)*25.71] \text in  {
    \colorbox {cyan} {0\textcolor{white}1},\colorbox {cyan} {0\textcolor{white}2},\colorbox {cyan} {0\textcolor{white}3},\colorbox {cyan} {0\textcolor{white}4}, \colorbox {cyan} {1\textcolor{white}0},\colorbox {cyan} {1\textcolor{white}1},\colorbox {cyan} {1\textcolor{white}2},\colorbox {cyan} {1\textcolor{white}3},\colorbox {cyan} {2\textcolor{white}0},\colorbox {cyan} {2\textcolor{white}1},\colorbox {cyan} {2\textcolor{white}2},\colorbox {cyan} {3\textcolor{white}0},\colorbox {cyan} {4\textcolor{white}0},\colorbox {cyan} {0\textcolor{white}0}, % Beschriftung der Kreise
}
\node[rotate=\angle, anchor=west] (node\i) at (\angle:0.8) {\text};

[
point/.default=5pt 
]

\foreach[count=\i,evaluate=\i as \angle using (\i)*25.71] \text in  {
    \colorbox {cyan} {0\textcolor{white}1},\colorbox {cyan} {0\textcolor{white}2},\colorbox {cyan} {0\textcolor{white}3},\colorbox {cyan} {0\textcolor{white}4}, \colorbox {cyan} {1\textcolor{white}0},\colorbox {cyan} {1\textcolor{white}1},\colorbox {cyan} {1\textcolor{white}2},\colorbox {cyan} {1\textcolor{white}3},\colorbox {cyan} {2\textcolor{white}0},\colorbox {cyan} {2\textcolor{white}1},\colorbox {cyan} {2\textcolor{white}2},\colorbox {cyan} {3\textcolor{white}0},\colorbox {cyan} {4\textcolor{white}0},\colorbox {cyan} {0\textcolor{white}0}, 
    \colorbox {cyan} {1\textcolor{white}1},\colorbox {cyan} {1\textcolor{white}2},\colorbox {cyan} {1\textcolor{white}3},\colorbox {cyan} {2\textcolor{white}0},\colorbox {cyan} {2\textcolor{white}1},\colorbox {cyan} {2\textcolor{white}2},\colorbox {cyan} {3\textcolor{white}0},\colorbox {cyan} {4\textcolor{white}0},\colorbox {cyan} {0\textcolor{white}0},
    \colorbox {cyan} {1\textcolor{white}1},\colorbox {cyan} {1\textcolor{white}2},\colorbox {cyan} {1\textcolor{white}3},\colorbox {cyan} {2\textcolor{white}0},\colorbox {cyan} {2\textcolor{white}1},\colorbox {cyan} {2\textcolor{white}2},\colorbox {cyan} {3\textcolor{white}0},\colorbox {cyan} {4\textcolor{white}0},\colorbox {cyan} {0\textcolor{white}0}, % Beschriftung der Kreise
}
\node[rotate=\angle, anchor=west] (node\i) at (\angle:1.8) {\text};

\end{tikzpicture}
%bis genau hier 
\end{document}

Dabei habe ich auch gleich den Fehler der geöffneten aber nie geschlossenen Gruppenklammer beseitigt.

Der Trick dabei ist, \colorbox lokal zur tikzpicture so umzudefinieren, dass vor der Ausführung der ursprünglichen \colorbox-Anweisung (jetzt zwischengespeichert in \saved@colorbox) der Zähler colorboxnum um eins erhöht wird. Die Umdefinierung wird von \countcolorbox erledigt. Dabei wird auch dafür gesorgt, dass bei mehrfachem Aufruf die Umdefinierung trotzdem nur einmal erfolgt. Mit dem Ende der tikzpicture-Umgebung verliert die Umdefinierung automatisch ihre Gültigkeit. Will man danach also erneut \colorbox zählen, benötigt man erneut ein \countcolorbox. Man kann die Wirkung auch mit Gruppenklammern begrenzen. Bei Bedarf kann man auch eine weitere Anweisung:

Open in Online-Editor
\newcommand*{\dontcountcolorbox}{%
  \ifx\saved@colorbox\@empty\else
    \let\colorbox\saved@colorbox
    \let\saved@colorbox\@empty
  \fi
}

definieren, mit der man ohne Gruppenende von gezählten \colorbox-Anweisungen auf nicht gezählte umschalten kann.

Das gleiche Prinzip kann man natürlich auch für andere Anweisungen verwenden. Für normale Wörter geht das so aber nicht.

Achja: Für obiges Beispiel wird in der Log-Datei ausgegeben: Es gab 46 relevante \colorbox Anweisungen.

Es gibt übrigens Umstände, unter denen die Zählung durcheinander kommen kann, beispielsweise wenn Code wie in einer longtable oder einer tabularx mehrfach gesetzt wird.

Permanenter link

beantwortet 04 Nov '15, 11:30

saputello's gravatar image

saputello
11.1k154365
Akzeptiert-Rate: 51%

Deine Antwort
Vorschau umschalten

Folgen dieser Frage

Per E-Mail:

Wenn sie sich anmelden, kommen Sie für alle Updates hier in Frage

Per RSS:

Antworten

Antworten und Kommentare

Markdown-Grundlagen

  • *kursiv* oder _kursiv_
  • **Fett** oder __Fett__
  • Link:[Text](http://url.com/ "Titel")
  • Bild?![alt Text](/path/img.jpg "Titel")
  • nummerierte Liste: 1. Foo 2. Bar
  • zum Hinzufügen ein Zeilenumbruchs fügen Sie einfach zwei Leerzeichen an die Stelle an der die neue Linie sein soll.
  • grundlegende HTML-Tags werden ebenfalls unterstützt

Frage-Themen:

×728
×52
×3

gestellte Frage: 21 Sep '15, 09:35

Frage wurde gesehen: 7,410 Mal

zuletzt geändert: 07 Feb '16, 11:37