! Missing \endcsname inserted.

3,029 views
Skip to first unread message

Neil Shephard

unread,
Oct 18, 2013, 5:27:16 AM10/18/13
to tufte...@googlegroups.com
Hi,

Really liking the clean and neat layout of this class but have encountered a problem I can not fathom or find reference to others encountering and would appreciate any assistance or pointers in resolving it.

I've tried narrowing down what is causing the error by commenting out sections and have this as an example....

<----- Begin master.tex ------>
\documentclass[fullpage]{tufte-book}\usepackage[]{graphicx}\usepackage[]{color}
\makeatletter
\def\maxwidth{ %
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother

\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%

\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
\def\at@end@of@kframe{}%
\ifinner\ifhmode%
\def\at@end@of@kframe{\end{minipage}}%
\begin{minipage}{\columnwidth}%
\fi\fi%
\def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
\colorbox{shadecolor}{##1}\hskip-\fboxsep
% There is no \\@totalrightmargin, so:
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
\MakeFramed {\advance\hsize-\width
\@totalleftmargin\z@ \linewidth\hsize
\@setminipage}}%
{\par\unskip\endMakeFramed%
\at@end@of@kframe}
\makeatother

\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX

\usepackage{alltt}

%% Load packages
\usepackage{alltt}
\usepackage{amsfonts}
\usepackage{appendix}
\usepackage{color}
\usepackage{fancybox}
\usepackage{fancyhdr}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{longtable}
\usepackage{lscape}
\usepackage{multirow}
\usepackage{pdflscape}
\usepackage{rotating}
\usepackage{tipx}
\usepackage{todonotes}
\usepackage{underscore}

%% Define new commands (from Tufte Class sample-book.tex)...
%%
%% Prints argument within hanging parentheses (i.e., parentheses that take
%% up no horizontal space). Useful in tabular environments.
\newcommand{\hangp}[1]{\makebox[0pt][r]{(}#1\makebox[0pt][l]{)}}

%% Prints an asterisk that takes up no horizontal space.
%% Useful in tabular environments.
\newcommand{\hangstar}{\makebox[0pt][l]{*}}

% Prints the month name (e.g., January) and the year (e.g., 2008)
\newcommand{\monthyear}{%
\ifcase\month\or January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or
December\fi\space\number\year
}
%% Prints an epigraph and speaker in sans serif, all-caps type.
\newcommand{\openepigraph}[2]{%
%%\sffamily\fontsize{14}{16}\selectfont
\begin{fullwidth}
\sffamily\large
\begin{doublespace}
\noindent\allcaps{#1}\\% epigraph
\noindent\allcaps{#2}% author
\end{doublespace}
\end{fullwidth}
}
%% Define \shortcite{} command (see https://groups.google.com/forum/#!topic/tufte-latex/4fKzsy-VRmI )
\newcommand{\shortcite}[1]{%
\sidenote{\citealt{#1}}%
}

%%------------------META INFORMATION------------------%%
\hypersetup{colorlinks}
\title{}
\author[]{}
\publisher{}
%%------------------META INFORMATION------------------%%




\makeindex
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}

\begin{document}

\maketitle


\chapter{Introduction}

Many clinical trials assess the effects of an intervention on some measurement of interest over time. An often used strategy for analysing data is to calculate the change, or percentage change, from baseline in the measurement of interest. Whilst this may be common practice it is widely acknowledged that there are a number of problems with such an approach~\sidenote{Many of these are summarised at \href{http://biostat.mc.vanderbilt.edu/wiki/Main/ManuscriptChecklist}{Statistical Problems to Document and to Avoid} (Deparment of Biostatistics, Vanderbilt University).}\ldots

\begin{itemize}
\item Analysing percentage change is less powerful than analysing the raw data~\shortcite{bland2011}~\shortcite{vickers2001b}~\shortcite{vickers2001}.
\item The change (absolute or percentage) can not be interpreted without reference to the baseline.
\item Interpretation is further complicated by the baseline measurement being on both sides of the regression model equation as heterogeneity at baseline must be accounted for.
\item Simple change scores are confounded by regression to the mean~\shortcite{bland1994a}~\shortcite{bland1994b}.
\item No meaningful summary statistics exist for percentage change beyond a minimum and maximum (without converting to log-ratios)~\sidenote{See \href{https://groups.google.com/d/msg/medstats/RtgXzWuVtMk/qYjY\_iDBlBIJ}{comment from Frank Harrell} on MedStats mailing list.}.
\end{itemize}

\begin{figure}[p]
{\centering \includegraphics[width=\maxwidth]{knitr/figures/litsearch}}
\caption{Trends in the use of search terms over time.\label{litsearch}}
\end{figure}


\end{document}
<----- End master.tex ------>

When I try to compile this using pdflatex (from texlive-latex-2013 under GNU/Linux) I get the following error message....

[5] (./master.aux
! Missing \endcsname inserted.
<to be read again>
\unhbox
l.29 \newpmemlabel{^_1}{3}

?

Sure enough within master.aux there is on line 29 the above...

$ grep -n newpmemlabel master.aux
29:\newpmemlabel{^_1}{3}

Playing around trying to work out what is causing this I narrowed it down to the image that is being included, so this section of code...

\begin{figure}[p]
{\centering \includegraphics[width=\maxwidth]{knitr/figures/litsearch}}
\caption{Trends in the use of search terms over time.\label{litsearch}}
\end{figure}

Commenting out the caption and the line that includes the graphic didn't get rid of the error, but removing the \begin{figure}[p] and \end{figure} (and the \caption{} which must be within a float environment!) did, suggesting to me that its a problem with including the float environment (my actual document so far has another table, and if I include that I have two of the above errors.

Searching around suggested that \newpmemlabel{}{} might be related to the memoir functions (?not sure if thats correct term) which is part of the 'mempatch' package, but including that in the list of packages used didn't help.

Any thoughts or ideas on how to troubleshoot this would be very gratefully received.

Regards

Neil

Kevin Godby

unread,
Oct 18, 2013, 7:50:40 PM10/18/13
to tufte-latex
Hello, Neil.

On Fri, Oct 18, 2013 at 4:27 AM, Neil Shephard <nshe...@gmail.com> wrote:
> When I try to compile this using pdflatex (from texlive-latex-2013 under
> GNU/Linux) I get the following error message....
>
> [5] (./master.aux
> ! Missing \endcsname inserted.
> <to be read again>
> \unhbox
> l.29 \newpmemlabel{^_1}{3}
>
> ?

The \newpmemlabel command is provided by the memoir document class,
the changepage package, and the poemscol package. (It's the same
definition in each case. The changepage and poemscol packages are
spin-offs of from the memoir document class.) In this case, the
Tufte-LaTeX document classes use the changepage package to create the
fullwidth environment and figures.

I spent some time with your example, commenting and uncommenting
chunks of it and it appears to be an issue with the underscore
package. If I comment out the underscore package, the document you
provided compiles successfully. (I also added the 'demo' option to the
graphicx package since I didn't have your actual graphics.)

From the 'underscore' package documentation: "You must avoid '_' in
file names and in cite or ref tags, or you must use the babel package,
with its active-character controls, or you must give the [strings]
option, which attempts to redefine several commands (and may not work
perfectly)."

I tried using \usepackage[strings]{underscore}, but it didn't work. It
looks like the underscore package doesn't redefine the \newpmemlabel
command for us.

Going forward, you have a few options:

1. Don't use the underscore package.

2. Redefine the label prefix used by the changepage package. You can
do this by adding the following line to your preamble before you load
the underscore package:

\def\cplabel{^X}

I don't know if this will solve all the problems or not, but it worked
for the sample document you provided.

3. Find a way to safely redefine the \newpmemlabel macro to work in
conjunction with the underscore package. You could ask on
http://tex.stackexchange.com/ for assistance with this.

Please let me know which solution you end up going with and how it
works for you.

Thanks!

—Kevin Godby

Neil Shephard

unread,
Oct 21, 2013, 5:02:51 AM10/21/13
to tufte...@googlegroups.com
Hi Kevin,


On Saturday, October 19, 2013 12:50:40 AM UTC+1, Kevin Godby wrote:
The \newpmemlabel command is provided by the memoir document class, 
the changepage package, and the poemscol package.  (It's the same
definition in each case. The changepage and poemscol packages are
spin-offs of from the memoir document class.)  In this case, the
Tufte-LaTeX document classes use the changepage package to create the
fullwidth environment and figures.

I spent some time with your example, commenting and uncommenting
chunks of it and it appears to be an issue with the underscore
package.  If I comment out the underscore package, the document you
provided compiles successfully. (I also added the 'demo' option to the
graphicx package since I didn't have your actual graphics.) 

Thanks for taking the time to dig through my problem.  It hadn't occurred to me that there may be conflicts between packages and to rifle through those to try and pin down which one it might be.  A useful strategy I shall try and remember to use in the future.

 
From the 'underscore' package documentation:  "You must avoid '_' in
file names and in cite or ref tags, or you must use the babel package,
with its active-character controls, or you must give the [strings]
option, which attempts to redefine several commands (and may not work
perfectly)."

I tried using \usepackage[strings]{underscore}, but it didn't work. It
looks like the underscore package doesn't redefine the \newpmemlabel
command for us.

Going forward, you have a few options:

1. Don't use the underscore package.

2. Redefine the label prefix used by the changepage package. You can
do this by adding the following line to your preamble before you load
the underscore package:

\def\cplabel{^X}

I don't know if this will solve all the problems or not, but it worked
for the sample document you provided.

3. Find a way to safely redefine the \newpmemlabel macro to work in
conjunction with the underscore package. You could ask on
http://tex.stackexchange.com/ for assistance with this. 

I included the \usepackage{underscore} as a throw back to when I was starting out with LaTeX and had a bad habit of using underscores.  Not being overly familiar with the ins and outs of redefining commands I opted for solution 1 and have omitted this from the list of packages I load in the pre-amble.

My larger document now compiles mostly fine (there are few other things I need to sort out, mainly floats and the text that follows starting on new pages, but thats a separate issue I shall investigate).

Thanks again for taking the time to help, very much appreciated.

Regards

Neil 
Reply all
Reply to author
Forward
0 new messages