0

The LaTeX build breaks because of Argument of \currency has extra }. This is strange since the output is (should be) the same as with \EURsimple...

\documentclass{article}

\usepackage[mode=text, group-digits=integer, group-minimum-digits = 4]{siunitx}

\sisetup{group-separator = {,}, input-decimal-markers={,.}, output-decimal-marker = {,}}

\newcommand{\EURsimple}[1] {% #1% }

\ExplSyntaxOn

\str_new:N \g__eur_length_str

\NewDocumentCommand{\setcurrencyformat}{m} { \str_gset:Nn \g__eur_length_str { #1 } }

\NewDocumentCommand{\currency}{om} { \currency_print_value:nnn { #1 } { #2 } { } }

\cs_new_protected:Nn \currency_print_value:nnn { \IfNoValueTF{#1} {% no optional argument \currency_print:Vnn \g__eur_length_str { #2 } { #3 } } {% optional argument present \currency_print:nnn { #1 } { #2 } { #3 } } }

\tl_new:N \l__currency_temp_tl

\cs_new_protected:Nn \currency_print:nnn { \str_if_eq:nnTF {#3} { } { % empty \tl_set:Nn \l__currency_temp_tl {} } { % not empty \tl_set:Nn \l__currency_temp_tl { \nobreakspace \unit{#3} } }

\str_case:nn { #1 }
{
    { full }    { \num[group-separator = {.}, minimum-decimal-digits = 2]{#2} \tl_use:N \l__currency_temp_tl }
    { standard }{ \num[group-separator = {.}, round-mode = places, round-precision = 2]{#2} \tl_use:N \l__currency_temp_tl }     
    { min }     { \num[group-separator = {.}, round-mode = places, round-precision = 0]{#2} \tl_use:N \l__currency_temp_tl }
    { noseparator }  { #2 } %\tl_use:N \l__currency_temp_tl }

} } \cs_generate_variant:Nn \currency_print:nnn { V }

\setcurrencyformat{full}

\ExplSyntaxOff

\begin{document}

\EURsimple{1234.56789} (EURsimple)

\currency[noseparator]{1234.56789} (currency[noseparator])

\begin{tabular}
    {
        S[table-format=5.4]
    }
    {\textbf{Einzelpreis}} \\
    1234.56789 \\
    13.45 \\    
    \EURsimple{1234.56789}  \\
    \EURsimple{13.45}\\
    \num{1234.56789}  \\          
    \num{13.45} \\              
    \currency{1234.56789}  \\     
    \currency{13.45}  \\         
    \currency[noseparator]{1234.56789} \\   % <= breaks ??
    \currency[noseparator]{13.45} \\       % <= breaks ??
\end{tabular}

\end{document}

The code breaks but runs if you comment the lines with the comment breaks???

P.S.: Because I shortened the code to create an MWE some functions seem to be unneccessarily split into two different functions. This is needed for the real code.

mrCarnivore
  • 1,505
  • 1
    You probably have to ask your self is that column suppose to be S formatted or not? S columns generally goes mad if you give them macros with [] arguments. What exactly are you trying to do in that column? It compiles it you protect it using {...} – daleif May 09 '23 at 15:23
  • 1
    The code as-written works fine: are we supposed to uncomment something? More generally, please try to make questions focussed on one thing: here, we have a lot of code that likely isn't relevant to the issue you are facing – Joseph Wright May 09 '23 at 15:24
  • @JosephWright: If you uncomment the bottom part (marked as breaks ??) it will not run. I do not understand why... I left it commented to show that the other parts run well. I cannot strip anything off the question. Everything is needed since I do not know what causes it... – mrCarnivore May 09 '23 at 15:26
  • 2
    you should provide an example of the problem, not a working example. You do not need to know the cause to make a more reasonable minimal example: simply delete every line you can delete while still showing the problem – David Carlisle May 09 '23 at 16:09
  • 2
    do you need this font to show the problem \usepackage{tgheros} ? If not, why is it in the example? – David Carlisle May 09 '23 at 16:11
  • 2
    see siunitx 9.5 Expanding content in tables – David Carlisle May 09 '23 at 16:17
  • @DavidCarlisle: siunitx 9.5 tells me to put {} around the command. It indeed prevents crashing. However, the numbers are not aligned with the decimal point. Also I do not understand why it works with \EURsimple this is also a command and should result in the same output. But it only works with that command but not \currency[noseparator]... – mrCarnivore May 09 '23 at 17:17
  • 3
    EURsimple is expandable so expands, \currency is \protected so as documented, does not expand – David Carlisle May 09 '23 at 17:27
  • Mmh, that sounds good, however, what would be the solution to solve it in my \currency command? Define it as \cs_new:Nn ? That also does not work. BTW: \currency[noseparator]also shows the wrong decimal point. There are so many things different to the\EURsimple` command... – mrCarnivore May 09 '23 at 17:32
  • I now have shortened the code even more and hope to have provided an MWE. – mrCarnivore May 09 '23 at 19:10
  • sorry but how on earth should siunitx be able to find the decimal point for alignment if you hide it in a layer of three non expandable commands?? (And by the way also the values with \num are not aligned for the same reason.) – Ulrike Fischer May 10 '23 at 07:48
  • @UlrikeFischer: I seem not to have grasped the concept of expandability completely. Afaik LaTeX takes the macro names and replaces it with its content and then continues to try to replace the content (expand) until no longer possible. Stopping by definition when something is not expandable. So I would understand that using a non expandable command definition will lead to problems. However, at some point before printing the commands still are expanded since the printed text fits. How and when is that done? – mrCarnivore May 11 '23 at 15:43
  • see e.g. https://tex.stackexchange.com/a/95590/2388 – Ulrike Fischer May 11 '23 at 15:57

0 Answers0