8

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."

  • 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
8
\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.

8

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.

6

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.

Your Answer

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

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