我希望将 N 个集成电路的数据存储在简单的 CSV 文件中,并让相应的文件在编译时驱动 LaTeX 文档。请参阅下面的 MWE,您就会明白我想要实现的目标。整个想法是拥有“单一信息源”,并且不必编辑除这些 CSV 文件之外的其他文件来更新文档。
梅威瑟:
\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}
示例输出:
答案1
好的,我使用数据工具找到了答案:
\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}