I want one function to specify some amount of white space. Here's what I've come up with for my .sty file:
\newcommand{\indentLength}{3} \newcommand{\indentUnit}{em} \newcommand{\indentFull}{\indentLength\indentUnit} \newcommand{\indents}[1]{ \ifthenelse{\greaterthan{#1}{0}}{\hspace{\indentFull}\indents{#1-1}}{} }
Then, I attempt to use \indent{1} on line 77 of my file. I get lots of repeats of the following output:
Latex Error: ./pks.tex:77 Undefined control sequence.
Latex Error: ./pks.tex:77 Missing number, treated as zero.
Latex Error: ./pks.tex:77 Missing = inserted for \ifnum.
Latex Error: ./pks.tex:77 Missing number, treated as zero.
This repeats over and over again, until I get
Latex Error: ./pks.tex:77 ==> Fatal error occurred, no output PDF file produced!
Is doing this possible? I really don't feel like typing things out over and over again...
Thanks a lot for the help.
Evan
-------------------------------------------------- The dinosaurs became extinct because they didn't have a space program.
Larry Niven
On 12/08/2008, at 9:17 AM, Evan Berkowitz wrote:
I want one function to specify some amount of white space.
Couple of problems with your macro :) Here's a working version:
\documentclass{article} \usepackage{ifthen} \begin{document} \newcommand{\indentLength}{3} \newcommand{\indentUnit}{em} \newcommand{\indentFull}{\indentLength\indentUnit} \newcommand{\indents}[1]{% \ifthenelse{\numexpr#1\relax>0}{% \hspace{\indentFull}% \indents{#1-1}}{}% } hello \indents{3} hello \end{document}
The ifthen package doesn't provide \greaterthan. Also, you need that \numexpr in order to evaluate the #1-1 expression before it's used in the conditional. Recursion with the ifthen package is a bit awkward :) Also note that there's a \whiledo command in ifthen, as well.
Anyway, there's an easier way to do what you're after:
\newlength\IND \setlength\IND{3em} hello \hspace*{3\IND} hello
I.e., you could use something like \newcommand\indents[1] {\hspace*{#1\IND}}.
Hope this helps, Will