TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a mathematical transformation that takes 16 parameters (grouped into 3+8+5) and would like to make a latex command for it, so that I can easily change the notation for it if the need arises.

As far as I know, both \def and \newcommand take a maximum of 9 arguments, is there any (recommended) way to extend this?

share|improve this question
3  
Perhaps you might show us the detail of what is wanted. This sounds like a question where the best answer will be to think carefully about the input you really require. – Joseph Wright Aug 21 '10 at 6:43
    
I edited the question to make it clear the parameters are not programmatic, but rather, an unavoidable part of the the maths that I'm using. – Simon Aug 21 '10 at 7:02
1  
I wonder if there's a magic solution involving Currying. – Seamus Feb 21 '13 at 16:19
up vote 29 down vote accepted

You are going to have to parse the arguments some at a time and store them into temporary registers or macros. For example

\newcommand\foo[9]{%
    \def\tempa{#1}%
    \def\tempb{#2}%
    \def\tempc{#3}%
    \def\tempd{#4}%
    \def\tempe{#5}%
    \def\tempf{#6}%
    \def\tempg{#7}%
    \def\temph{#8}%
    \def\tempi{#9}%
    \foocontinued
}
\newcommand\foocontinued[7]{%
    % Do whatever you want with your 9+7 arguments here.
}
share|improve this answer
    
Thanks TH - that's the same solution as supplied in the "black TeX magic" link provided by mindcorrosive. I think that I'll use the xargs package, since it will make my code clearer and I like the simple default arguments. – Simon Aug 21 '10 at 6:55
1  
Can you give an example of how to declare and access/use the variables? – FireFly3000 Oct 15 '15 at 15:10
    
I ask the same question as @FireFly3000 . I did as you said above and called the two functions as follows: \pointscolors{100}{red}; \myarc{0}{0}{0}{0}{3}{2.645751311064591}{0}{-3}{2.645751311064591}; (sorry, I do not know how to format this), with 2 arguments and the next with 9 arguments. then I get this error: Argument of \myarc has an extra }. <inserted text> \par l.90 ...myarc{0}{0}{0}{0}{3}{2.645751311064591}{0} {-3}{2.645751311064591}; ? – Herman Jaramillo Nov 2 '15 at 23:01
    
I removed the "\foocontinued" from the first block (named "\foo") and my error disappeared. I think that line is in error because is called without parameters. – Herman Jaramillo Nov 2 '15 at 23:32

Since it's a different technique, I also present the following: local macro definitions.

\documentclass{article}

\def\NineteenArgs#1#2#3#4#5#6#7#8#9{%
    \def\ArgsTenAndFurther##1##2##3##4##5##6##7##8##9{%
        \def\ArgNineteen####1{%
            ####1##9##8##7##6##5##4##3##2##1#9#8#7#6#5#4#3#2#1%
        }%
        \ArgNineteen%
    }%
    \ArgsTenAndFurther%
}

\begin{document}
                 %1234567890123456789
    \NineteenArgs abcdefghijklmnopqrs
\end{document}
share|improve this answer

In a response to How to use variables inside a command when generating a table? I mention how the stringstrings package has a \getargs command that will parse large numbers of arguments that are passed within a single { }. To recap that reply,

\documentclass{article}
\usepackage{stringstrings}
\begin{document}
\getargs{1 2 3 4 5 6 7 8 9 10 11 12 FinalArgument}
There are \narg~arguments.  The thirteenth is \argxiii
\end{document}

The result to this example is:

There are 13 arguments. The thirteenth is FinalArgument


EDIT: A much more efficient version of \getargs is available in the readarray package and called \getargsC (in deference to David Carlisle's help). Thus, the same task can be accomplished more quickly with

\documentclass{article}
\usepackage{readarray}
\begin{document}
\getargsC{1 2 3 4 5 6 7 8 9 10 11 12 FinalArgument}
There are \narg~arguments.  The thirteenth is \argxiii
\end{document}
share|improve this answer

There's the xargs package, and there's also some black TeX magic. As for myself, being conditioned in Python, I prefer the key-value parameter syntax provided by keyval/xkeyval packages.

On an unrelated note, if I find myself needing more than 9 parameters, that usually means that my macro/def/code organization is not very good, and I'd try to improve that first. But of course, there are legitimate situations where 9 parameters are perfectly okay --- especially if you try to build a definition with a lot of knobs and tweaks.

share|improve this answer
    
Thanks, I don't know how my googling did not turn up the first option you gave. The 16 parameters define a nonlinear transformation - they're not options in the macro. – Simon Aug 21 '10 at 6:51
    
Actually, xargs does not allow more than 9 arguments - it only gives a neat interface for optional arguments. I'll have to use the TeX hack. – Simon Aug 21 '10 at 7:10
3  
That's correct. Until you clarified what you need so much parameters for, I assumed it's for a macro, and you'd use the keyval interface. But of course in that case it's better with plain TeX. – Martin Tapankov Aug 21 '10 at 7:15
    
Actually you made me reconsider if I needed all those arguments and I ended up with 6 arguments in stead of 10 :) – FireFly3000 Oct 15 '15 at 16:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.