我正在尝试测试 csv 数据中的某些宏,并获得了非常特殊的结果。
测试 1(查看命令\csvautobooktabular{macrodata.csv}
):
\documentclass[a4paper,9pt]{book}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{csvsimple}
\usepackage{hyperref}
\usepackage{tikz}
\begin{document}
\begin{filecontents*}{macrodata.csv}
type,description,content
M,A nice \textbf{formula}, $\displaystyle \int\frac{1}{x} = \ln|x|+c$
G,A \textcolor{red}{colored} ball, {\tikz \shadedraw [shading=ball] (0,0) circle (.5cm);}
M,\textbf{Another} formula, $\displaystyle \lim\limits_{n\to\infty} \frac{1}{n}=0$
\end{filecontents*}
\begin{filecontents*}{data.csv}
clé,nom,valeur
var1,numeric,32+1
var2,string,"text"
var3,float,3.14-x
var4,Latex,test
\end{filecontents*}
\csvautobooktabular{macrodata.csv}
\section{Variables}\label{sec:var}
\begin{landscape}
\csvloop{
file=data.csv,
respect all,
separator=comma,
no head,
column names={1=\cola, 2=\colb, 3=\colc},
before reading={
\begin{table}
\centering
\begin{tabular}{llr}
\toprule
},
command={\csviffirstrow
{\textbf{\cola} & \textbf{\colb} & \textbf{\colc}}
{\addtocounter{csvrow}{-1}\hyperref[sec:a-\thecsvrow]{\cola}\addtocounter{csvrow}{1} & \colb & \colc}
},
late after line=\\,
late after first line=\\\midrule,
late after last line=\\\bottomrule,
after reading={
\end{tabular}
\caption{Liste des entités}
\label{tab:variables}
\end{table}
}
}
\end{landscape}
\subsection{Variable 1}\label{sec:a-1}
\dots
\subsection{Variable 2}\label{sec:a-2}
\dots
\subsection{Variable 3}\label{sec:a-3}
\dots
\subsection{Variable 4}\label{sec:a-4}
\dots\newline
\end{document}
这个测试似乎运行正常:
现在进行第二项测试:
\documentclass[a4paper,9pt]{book}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{csvsimple}
\usepackage{hyperref}
\usepackage{tikz}
\begin{document}
\begin{filecontents*}{macrodata.csv}
type,description,content
M,A nice \textbf{formula}, $\displaystyle \int\frac{1}{x} = \ln|x|+c$
G,A \textcolor{red}{colored} ball, {\tikz \shadedraw [shading=ball] (0,0) circle (.5cm);}
M,\textbf{Another} formula, $\displaystyle \lim\limits_{n\to\infty} \frac{1}{n}=0$
\end{filecontents*}
\begin{filecontents*}{data.csv}
clé,nom,valeur
var1,numeric,32+1
var2,string,"text"
var3,float,3.14-x
var4,Latex,test
\end{filecontents*}
\section{Variables}\label{sec:var}
\begin{landscape}
\csvloop{
file=data.csv,
respect all,
separator=comma,
no head,
column names={1=\cola, 2=\colb, 3=\colc},
before reading={
\begin{table}
\centering
\begin{tabular}{llr}
\toprule
},
command={\csviffirstrow
{\textbf{\cola} & \textbf{\colb} & \textbf{\colc}}
{\addtocounter{csvrow}{-1}\hyperref[sec:a-\thecsvrow]{\cola}\addtocounter{csvrow}{1} & \colb & \colc}
},
late after line=\\,
late after first line=\\\midrule,
late after last line=\\\bottomrule,
after reading={
\end{tabular}
\caption{Liste des entités}
\label{tab:variables}
\end{table}
}
}
\end{landscape}
\subsection{Variable 1}\label{sec:a-1}
\dots
\subsection{Variable 2}\label{sec:a-2}
\dots
\subsection{Variable 3}\label{sec:a-3}
\dots
\subsection{Variable 4}\label{sec:a-4}
\dots\newline
\csvautobooktabular{macrodata.csv}
\end{document}
因此,我只是将csvautobooktabular
命令移到文档的末尾,令人惊讶的是,在第二种情况下,它给了我一个如下所示的表格:
显然,在第二次测试中,数据文件中的宏不再起作用。这是为什么?我的错误在哪里?
答案1
该选项键respect all
将所有特殊字符转换为普通文本。
用来respect none
让它们再次变得特别。
平均能量损失
\begin{filecontents*}{macrodata.csv}
type,description,content
M,A nice \textbf{formula}, $\displaystyle \int\frac{1}{x} = \ln|x|+c$
G,A \textcolor{red}{colored} ball, {\tikz \shadedraw [shading=ball] (0,0) circle (.5cm);}
M,\textbf{Another} formula, $\displaystyle \lim\limits_{n\to\infty} \frac{1}{n}=0$
\end{filecontents*}
\begin{filecontents*}{data.csv}
clé,nom,valeur
var1,numeric,32+1
var2,string,"text"
var3,float,3.14-x
var4,Latex,test
\end{filecontents*}
\documentclass[a4paper,9pt]{book}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage[legacy]{csvsimple}
\usepackage{hyperref}
\usepackage{tikz}
\begin{document}
\csvautobooktabular{macrodata.csv}
\csvloop{
file=data.csv,
respect all,
separator=comma,
no head,
column names={1=\cola, 2=\colb, 3=\colc},
before reading={
\begin{table}
\centering
\begin{tabular}{llr}
\toprule
},
command={\csviffirstrow
{\textbf{\cola} & \textbf{\colb} & \textbf{\colc}}
{\addtocounter{csvrow}{-1}\hyperref[sec:a-\thecsvrow]{\cola}\addtocounter{csvrow}{1} & \colb & \colc}
},
late after line=\\,
late after first line=\\\midrule,
late after last line=\\\bottomrule,
after reading={
\end{tabular}
\caption{Liste des entités}
\label{tab:variables}
\end{table}
}
}
respect all
\csvautobooktabular{macrodata.csv}
repect none
\csvautobooktabular[respect none]{macrodata.csv}
\end{document}
附录:
稍微整理了一下 csvloop 代码,考虑到自动按键设置。
平均能量损失
\begin{filecontents*}{macrodata.csv}
type,description,content
M,A nice \textbf{formula}, $\displaystyle \int\frac{1}{x} = \ln|x|+c$
G,A \textcolor{red}{colored} ball, {\tikz \shadedraw [shading=ball] (0,0) circle (.5cm);}
M,\textbf{Another} formula, $\displaystyle \lim\limits_{n\to\infty} \frac{1}{n}=0$
\end{filecontents*}
\begin{filecontents*}{data.csv}
clé,nom,valeur
var1,numeric,32+1
var2,string,"text"
var3,float,3.14-x
var4,Latex,test
\end{filecontents*}
\documentclass[a4paper,9pt]{book}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage[legacy]{csvsimple}
\usepackage{hyperref}
\usepackage{tikz}
\begin{document}
\csvautobooktabular{macrodata.csv}
\csvloop{
file=data.csv,
% respect all,
separator=comma,
no head,
before table={
\begin{table}
\centering
},
tabular={llr},
table head={
\toprule
},
table foot={\bottomrule},
column names={1=\cola, 2=\colb, 3=\colc},
command={\csviffirstrow
{\textbf{\cola} & \textbf{\colb} & \textbf{\colc}}
{\addtocounter{csvrow}{-1}\hyperref[sec:a-\thecsvrow]{\cola}\addtocounter{csvrow}{1} & \colb & \colc}
},
after first line=\\\midrule,
late after first line=,
after table={
\caption{Liste des entités}
\label{tab:variables}
\end{table}
},
}
\csvautobooktabular{macrodata.csv}
\csvautobooktabular[respect none]{macrodata.csv}
\end{document}