TeXhackse / LaTeX-ZUGFeRD

LaTeX packages to create ZUGFeRD/Faktur-X invoices
33 stars 8 forks source link

Using koma variables for zugferd data #18

Closed t-b closed 2 weeks ago

t-b commented 2 weeks ago

(I'm pretty sure this is a standard latex question but I'm not really good at this.)

I would like to use komascript variables for the zugferd data entries to avoid duplication of values.

Now from glancing at the package code, and https://tex.stackexchange.com/a/532873/77589, I managed to cargo cult something like

\newkomavar{companyname-plain}
\setkomavar{companyname-plain}{ACME Inc.}

\newkomavar{fromname}
\setkomavar{fromname}{My Name}

\SetZUGFeRDData*{
    document-type = commercial-invoice,
    seller/name = {\csname scr@companyname-plain@var\endcsname\space(\csname scr@fromname@var\endcsname)},
}
    payment-terms={Zahlbar innerhalb von \csname scr@payment-terms-duration@var\endcsname},
}

together. But it's hideous to use and look at.

I've tried the obvious

\def\rawkomavalue#1{\csname scr@#1@var\endcsname}

to wrap the calls but that does not work. Is there a more elegant way?

TeXhackse commented 2 weeks ago

Generally this works. Though you could juse use \UseName{…} instead of \csname …\endcsname nowerdays or the expl3 c-type.

I guess the issue you face comes from the timing. You seem to set that variable before the komavar is set.

So you have to ensure to pass the value before you do the expansion, which you do at the moment of \SetZUGFeRDData* by using the starred version. You could use a hook or something like \AtBeginLetter to do that later.

t-b commented 2 weeks ago

Thanks, using \UseName did the trick.

I'm now using

\newkomavar{postcode}
\setkomavar{postcode}{01234}

\newcommand{\expandkomavar}[1]{\UseName{scr@#1@var}}

\SetZUGFeRDData*{
    document-type = commercial-invoice,
    seller/postcode = \expandkomavar{postcode},
}

which works.