Text Formatting`macro parameter character #' in horizontal mode

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
ChelseaBoot
Posts: 7
Joined: Fri Jun 17, 2011 9:54 am

`macro parameter character #' in horizontal mode

Post by ChelseaBoot »

I am trying to create a template for problem sets using another template I found online, a minimal example of which is below. When I try to compile this, I get the error:
You can't use `macro parameter character #' in horizontal mode
There are other instances of this error report on google but most of those seem to be associated with bug reports of various forms. Not sure what is going wrong here...

Code: Select all

\documentclass[a4paper]{article}

\usepackage{amsmath,amsfonts,amssymb}
\usepackage{color,enumerate}
\usepackage{hyperref}


\newcommand{\profs}{Professor A}
\newcommand{\subj}{Subject B}

\newlength{\toppush}
\setlength{\toppush}{2\headheight}
\addtolength{\toppush}{\headsep}

% newcommand - htitle
\newcommand{\htitle}[2]{
\noindent\vspace*{-\toppush}\newline\parbox{6.5in}
%1
{\textit{Subject B}\hfill\newline
University of Brobdingnag \hfill #2\newline
\profs\newline
\mbox{}\hrulefill\mbox{}}
%2
\vspace*{1ex}\mbox{}\newline
\begin{center}
{\Large\bf #1}
\end{center}
}

% newcommand - handout
\newcommand{\handout}[3]{
\thispagestyle{empty}
 \markboth{Problem set #1}{Problem set #1}
 \pagestyle{myheadings}
 \htitle{#2}{#3}
 }

\setlength{\oddsidemargin}{0pt}
\setlength{\evensidemargin}{0pt}
\setlength{\textwidth}{6.5in}
\setlength{\topmargin}{0in}
\setlength{\textheight}{8.5in}

\begin{document}
\handout{4}{Problem Set #1}{\today}
\begin{center}

\end{center}
\begin{enumerate}
\item 
\item 
\item
  \end{enumerate}
\end{document}
Last edited by ChelseaBoot on Fri Jun 17, 2011 3:42 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
TikZ book
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

`macro parameter character #' in horizontal mode

Post by localghost »

You should take a closer look at the exact error message in the log file. The compiler also gives you the line where the error occurs.

Code: Select all

! You can't use `macro parameter character #' in horizontal mode.
<argument> Problem Set ##
                         1
l.44 \handout{4}{Problem Set #1}{\today}
So it is no problem to fix it. You are trying to use a character that is exclusively reserved as macro parameter character when defining new macros. If you want to have it as output, you have to insert \# in your source.

Code: Select all

\handout{4}{Problem Set \#1}{\today}
If you want to typeset a problem sheet, you may take a look at the exam class.


Best regards and welcome to the board
Thorsten
ChelseaBoot
Posts: 7
Joined: Fri Jun 17, 2011 9:54 am

Re: `macro parameter character #' in horizontal mode

Post by ChelseaBoot »

Thanks for that Thorsten. My understanding of macros is poor - I thought the "#1" in the second input of \handout would get dereferenced using the first input to the \handout command. Now that seems a little silly. :)
Post Reply