0

I am trying to test some macros inside csv data and I am obtaining very special results.

Test number 1 (look at the command \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}

This test seems to work correctly:

enter image description here

Now the second test:

\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}

Consequently, I just moved the csvautobooktabular command to the end of the document and surprisingly, in the second case, it gave me a table that looks like this:

enter image description here

Clearly, in the second test macros inside the data file are not functional anymore. Why is this and where is my mistake?

JamesT
  • 3,169
Certes
  • 35

1 Answers1

1

The option key respect all converts all special characters to ordinary text.

Use respect none to make them special again.

csvsimple

MWE


\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}


Addendum:

Slightly tidied up the csvloop code, taking into account automatic key settings.

version 2

MWE


\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}

Cicada
  • 10,129