2

I have the following csv file (myCSVfile.csv) which contains header with LaTeX code:

$T_{1,2}$, $T_{3}$
100, 300
200, 500

In my LaTeX document, I import this table with \pgfplotstabletypeset[col sep=comma,row sep=newline]{myCSVfile.csv}.

It works well but my csv file is not satisfying for me because some comma are note column separators but just characters in a math expression in header titles, as in: $T_{1,2}$

I there a native command that just print a comma in math mode, e.g.: $T_{1\comma{}2}$ instead of $T_{1,2}$ which output nearly the same in the pdf ?. In text mode it would also be OK for me even if it's not the best solution: $T_{1\text{\comma{}}2}$.

I found the \mathpunct command here but there is still a comma when I use it in the csv file : $T_{1\mathpunct{,}2}$ instead of $T_{1,2}$ and I get an error when importing with \pgfplotstabletypeset...

I know that I can just put my header title between double quotes "$T_{1,2}$" to be sure that the comma in header title will not be interpreted as column separator, but I wonder if there is a way to obtain a comma with a native command in math mode or even in text mode.

MWE:

\documentclass{article}
\usepackage{pgfplotstable,filecontents}

\begin{filecontents*}{myCSVfile.csv}
$T_{1,2}$, $T_{3}$
100,      300     
200,      500     
\end{filecontents*}

\begin{document}
    \pgfplotstabletypeset[col sep = comma,row sep=newline]{myCSVfile.csv}
\end{document}
3
  • 1
    \newcommand{\comma}{,}
    – egreg
    Commented Sep 14, 2022 at 9:19
  • Thanks for your comment. What appends if I give my csv file to someone else, I need to tell this person what \comma is ? I would prefer more "portable" solution...
    – zetyty
    Commented Sep 14, 2022 at 9:27
  • Use the quotes. There is no “self-defining command”
    – egreg
    Commented Sep 14, 2022 at 9:30

1 Answer 1

3

I would use "$T_{1,2}$" as that will be easily understood by any software or human reading the csv file. However comma is ASCII decimal 44, hex 2C so you can use ^^2c if you wish:

\documentclass{article}
\usepackage{pgfplotstable,filecontents}

\begin{filecontents*}{myCSVfile.csv}
$T_{1^^2c 2}$, $T_{3}$
100,      300     
200,      500     
\end{filecontents*}

\begin{document}
    \pgfplotstabletypeset[col sep = comma,row sep=newline]{myCSVfile.csv}
\end{document}
2
  • Perfect, thanks a lot ! Could you explain the ^^2c syntax ? Especially the ^^ ?
    – zetyty
    Commented Sep 14, 2022 at 10:18
  • @SylvainRigal this is low level syntax ^^ followed by a captital shifts the character code by 64 so ^^M is control-m, or ^^ followed by two lowercase hex digits is that character. This is at a very early stage, before tokenization, eg \be^^67in is \begin because g is ascii hex 67 Commented Sep 14, 2022 at 10:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .