
N개의 집적 회로에 대한 데이터를 간단한 CSV 파일에 저장하고 해당 파일이 컴파일 시 LaTeX 문서를 구동하게 되기를 바라고 있습니다. 아래 내 MWE를 보면 내가 무엇을 성취하고 싶은지 알 수 있습니다. 전체 아이디어는 "단일 정보 소스"를 갖고 문서를 업데이트하기 위해 이러한 CSV 파일 이상을 편집할 필요가 없다는 것입니다.
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}
예제 출력:
답변1
좋아, datatool을 사용하여 알아냈습니다.
\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}