Generalreadarray + siunitx and macro expansion fails

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
gallioleo
Posts: 13
Joined: Thu Nov 18, 2021 6:35 pm

readarray + siunitx and macro expansion fails

Post by gallioleo »

Hello Latex Community,

i try to read values from a csv file and propagate it into the package siunitx. But siunitx expects values und no macro code. How can i expand it to the real value? Below the MWE:

Code: Select all

Code, edit and compile here:
\documentclass[
fontsize=12pt,% changed because of the package info in the log file
DIV=14
]{scrreprt}
\usepackage[english]{babel}
\usepackage[binary-units=true, detect-all]{siunitx}[=v2]
\usepackage{readarray}
\usepackage{xifthen}
% siunitx settings
\sisetup {
exponent-to-prefix = true, % convert exponents into belonging prefixes
round-mode = places,
scientific-notation = engineering,% try to use next engineering unit instead of '.'
per-mode = symbol,
per-symbol = /
}
% Introduces command \csvvalfile[separator]{file.csv} and stores result in \csvvalfield{row, column}
%
% https://tex.stackexchange.com/questions/562789/how-to-look-up-a-cell-value-of-a-multi-column-csv-file
% https://tex.stackexchange.com/questions/301665/error-when-using-num-command-from-siunitx-package-with-an-array-from-arrayjob-p
\newcommand{\csvvalfile}[2][]{%
% https://stackoverflow.com/questions/2144176/latex-newcommand-default-argument-is-empty
\ifthenelse{\isempty{#1}} {%default separator
\readarraysepchar{,}
} {% else
\readarraysepchar{#1}
}%
\hypercheckbounds
\readdef{#2}\csvvaldata
\readarray\csvvaldata\csvvalfielddata[-,\ncols]
}
\newcommand{\csvvalfield}[1]{%
\arraytomacro\csvvalfielddata[#1]\csvvalfieldval
\csvvalfieldval
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Thanks for your Help!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

readarray + siunitx and macro expansion fails

Post by Stefan Kottwitz »

Hi,

this should work:

Code: Select all

\SI[parse-numbers = false]{\csvvalfield{3,2}}{\volt}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Stefan
LaTeX.org admin
Post Reply