
Ich möchte Daten für N integrierte Schaltkreise in einfachen CSV-Dateien speichern und die entsprechende Datei beim Kompilieren das LaTeX-Dokument steuern lassen. Sehen Sie sich mein MWE unten an und Sie sehen, was ich erreichen möchte. Die ganze Idee besteht darin, „eine einzige Informationsquelle“ zu haben und nicht mehr als diese CSV-Dateien bearbeiten zu müssen, um das Dokument zu aktualisieren.
MWE:
\documentclass[]{book}
\usepackage{datatool}
\usepackage[siunitx]{circuitikz}
\usepackage{currfile}
\usepackage{pgfplotstable}
\pgfplotstableset{col sep=semicolon, string type}
\usepackage{filecontents}
\begin{document}
\begin{filecontents*}{\currfilebase_pinout.csv}
1;Q1;Output 1
2;Q2;Output 2
3;Q3;Output 3
4;Q4;Output 4
5;Q5;Output 5
6;Q6;Output 6
7;Q7;Output 7
8;GND;Ground
9;Q7S;bla
10;/MR;bla
11;SHCP;bla
12;STCP;bla
13;/OE;bla
14;DS;bla
15;Q0;Output 8
16;VCC;2-6V
\end{filecontents*}
\begin{figure}[ht]
\centering
\begin{circuitikz}
\draw (0,0) node[dipchip, num pins=16 ](C){\rotatebox{90}{\currfilebase}}; %num pins=... here I would be happy if datatool could give me the number of entries in the source file
% ------------------- FROM HERE -------------------
\node [left, font=\tiny] at (C.pin 1) {Q1};
\node [left, font=\tiny] at (C.pin 2) {Q2};
\node [left, font=\tiny] at (C.pin 3) {Q3};
\node [left, font=\tiny] at (C.pin 4) {Q4};
\node [left, font=\tiny] at (C.pin 5) {Q5};
\node [left, font=\tiny] at (C.pin 6) {Q6};
\node [left, font=\tiny] at (C.pin 7) {Q7};
\node [left, font=\tiny] at (C.pin 8) {GND};
\node [right, font=\tiny] at (C.pin 9) {Q7S};
\node [right, font=\tiny] at (C.pin 10) {/MR};
\node [right, font=\tiny] at (C.pin 11) {SHCP};
\node [right, font=\tiny] at (C.pin 12) {STCP};
\node [right, font=\tiny] at (C.pin 13) {/OE};
\node [right, font=\tiny] at (C.pin 14) {DS};
\node [right, font=\tiny] at (C.pin 15) {Q0};
\node [right, font=\tiny] at (C.pin 16) {VCC};
% ------------------- TO HERE ------------------- i would be happy if a macro could populate these data from the source file
\end{circuitikz}
\caption{\currfilebase\ pinout}
\end{figure}
\begin{table}[ht]
\centering
\pgfplotstabletypeset{\currfilebase_pinout.csv}
\caption{\currfilebase\ pinout explanation}
\end{table}
\end{document}
Beispielausgabe:
Antwort1
Ok, ich habe es mit Datatool herausgefunden:
\documentclass[]{book}
\usepackage[siunitx]{circuitikz}
\usepackage{currfile}
\usepackage{pgfplotstable}
\pgfplotstableset{col sep=semicolon, string type}
\usepackage{datatool}
\DTLsetseparator{;}
\usepackage{filecontents}
\begin{document}
\begin{filecontents*}{\currfilebase_pinout.csv}
1;Q1;Output 1
2;Q2;Output 2
3;Q3;Output 3
4;Q4;Output 4
5;Q5;Output 5
6;Q6;Output 6
7;Q7;Output 7
8;GND;Ground
9;Q7S;bla
10;/MR;bla
11;SHCP;bla
12;STCP;bla
13;/OE;bla
14;DS;bla
15;Q0;Output 8
16;VCC;2-6V
\end{filecontents*}
\DTLloaddb[noheader,keys={Pin,Label,Info}]{csvData}{\currfilebase_pinout.csv}
\DTLmaxforcolumn{csvData}{Pin}{\numberOfPins}
\begin{figure}[ht]
\centering
\begin{circuitikz}
\draw (0,0) node[dipchip, num pins=\numberOfPins ](C){\rotatebox{90}{\currfilebase}};
\DTLforeach{csvData}{\pinNumber=Pin, \label=Label}{
\DTLdiv{\checkValue}{\pinNumber}{\numberOfPins}
\ifthenelse{\DTLisgt{\checkValue}{0.5}}
{\node [right, font=\tiny] at (C.pin \pinNumber) {\label};}
{\node [left, font=\tiny] at (C.pin \pinNumber) {\label};}
}
\end{circuitikz}
\caption{\currfilebase\ pinout}
\end{figure}
\begin{table}[ht]
\centering
\pgfplotstabletypeset{\currfilebase_pinout.csv}
\caption{\currfilebase\ pinout explanation}
\end{table}
\end{document}