Take the 2-minute tour ×
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.

I thought that doubling hashes was sufficient to pass arguments to nested \newcommand.

\newcommand{\notice}[1]{
  \vspace{10px}
  \textbf{#1:}
  \begin{quotation}
    ##1
  \end{quotation}}

\newcommand{\hint}[1]{
  \notice{Hint}
}

What am I doing wrong here? The above produces the following error:

"You can't use `macro parameter character #' in vertical mode."

share|improve this question
3  
This is not what is typically considered "nested". What is it you're trying to do? –  Werner Jul 24 '12 at 16:27
1  
In particular, if you replace ##1 by #1 does it do what you want? –  David Carlisle Jul 24 '12 at 16:32

3 Answers 3

up vote 8 down vote accepted
\newcommand{\notice}[2]{
  \vspace{10px}
  \textbf{#1:}
  \begin{quotation}
    #2
  \end{quotation}}

\newcommand{\hint}[1]{%
  \notice{Hint}{#1}%
}

You'll need the double hashes only if you \def something in a \def.

share|improve this answer

What you've done is put the string #1 inside the quotation. Such an operation only makes sense if you are defining a macro inside of another one, and you want that macro to make reference to its own first argument rather than have the #1 of the outer macro substituted. For example, in:

\newcommand\macroia[1]{\renewcommand\macroii[1]{#1}}
\newcommand\macroib[1]{\renewcommand\macroii[1]{##1}}
\providecommand\macroii{}

the call \macroia{xyz} results in \macroii{#1} = xyz, i.e. it ignores its own argument and just prints whatever \macroia saw, while the call \macroia{xyz} results in \macroii{#1} = #1; i.e. it ignores the argument to \macroia and just echoes whatever it is passed when expanded.

share|improve this answer

I'm doing some guesswork here. I believe that you want a boldface header to some text typeset with narrower line width. What you need is a new environment, not a new command:

\newenvironment{notice}[1]
  {\par\medskip\textbf{#1}\begin{quotation}}
  {\end{quotation}

so that you can input somethin like

\begin{notice}{Hint}
This is a very useful hint for solving the problem.
\end{notice}

The result won't be pretty, though. I'd place the heading inside the text:

\newenvironment{notice}[1]
  {\begin{quotation}\noindent\textbf{#1}\\*\ignorespaces}
  {\end{quotation}}

(same syntax as before). Also \hint should be an environment:

\newenvironment{hint}
  {\begin{notice}{Hint}}
  {\end{notice}}

Don't use spaces at random (\vspace{10px}, for instance), but above all don't use px to specify lengths. This is a unit that doesn't have a fixed value and is definitely not analogous to what the similar unit does in HTML or CSS.

share|improve this answer

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.