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}

zetyty
  • 779

1 Answers1

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}

David Carlisle
  • 757,742
  • Perfect, thanks a lot ! Could you explain the ^^2c syntax ? Especially the ^^ ? – zetyty Sep 14 '22 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 – David Carlisle Sep 14 '22 at 10:48