0

I'm currently facing the problem that I don't know how to properly put a macro with an optional argument as an argument inside \input.

If I use something like this

\newcommand{\test}[1][Hi]{#1}
\input{\test}

I am getting an endless loop during compilation and the console spits out this:

kpathsea: Running mktextfm at0

mktextfm: Running mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input at0

This is METAFONT, Version 2.7182818 (TeX Live 2017/Arch Linux) (preloaded base=mf) kpathsea: Running mktexmf at0

! I can't find file `at0'. <*> \mode:=ljfour; mag:=1; nonstopmode; input at0 Please type another input file name ! Emergency stop. <*> \mode:=ljfour; mag:=1; nonstopmode; input at0 Transcript written on mfput.log.

grep: at0.log: No such file or directory

mktextfm: `mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input at0' failed to make at0.tfm.

kpathsea: Appending font creation commands to missfont.log.

However the actual case in which I need this is the following code:

\newcommand{\regression}[1]{\input{|"java -jar /home/raven/Documents/Programming/Regression.jar #1"}}
\newcommand{\logarithmic}[1][e]{-mode=log-#1 }

\regression{
    \logarithmic
}

When compiling the above code latex throws an error stating \\logarithmic does not match its definition. } When removing the optional argument from \logarithmic everything works just fine.

I have googled the error message and it always pointed to some problem concerning fragile commands but I couldn't get it working using either \protected or \DeclareRobustCommand.

Also what seems strange to me is that in the first example the optional argument is causing an endless loop wheras in the second example it gives mne that error message... Can anyone help me understanding what's going on and how to solve my problem?

  • You essentially can't. the argument to \regression must be fully expandable and a command with an optional argument isn't. – egreg Nov 26 '17 at 13:34
  • So there's no way of somehow hacking around that? – Raven Nov 26 '17 at 13:41
  • Define your command with a mandatory argument – egreg Nov 26 '17 at 13:42
  • Hm that's bad news... But if that is the way it is you can add an answer with your comment's content and I will accept it. – Raven Nov 26 '17 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.