I could have sworn that I stole the code from tabularx
that resets LaTeX counters after a trial run but apparently not so....
(Note you should probably use \jobname.foo
as the temporary file name, it is a bit scary that it overwrites any file of that name when run.
\documentclass[a4paper]{article}
\usepackage[margin=3cm]{geometry}
\usepackage{tabulary}
\usepackage[newcommands]{ragged2e}
\usepackage{array}
\tymin=0.1\textwidth
\tymax=10\textwidth
\renewcommand{\tabcolsep}{0cm}
\newcommand{\colspace}{1em}
\AtBeginDocument{\edef\normalparindent{\the\parindent}}
\newcounter{localsidenotecounter}
\newwrite\tempfile
\makeatletter
\def\endtabulary{%
\gdef\@halignto{}%
\def\@elt##1{\global\value{##1}\the\value{##1}\relax}%
\edef\TY@ckpt{\cl@@ckpt}%
\expandafter\TY@tab\the\toks@
\crcr\omit
{\xdef\TY@save@row{}%
\loop
\advance\TY@count\m@ne
\ifnum\TY@count>\z@
\xdef\TY@save@row{\TY@save@row&\omit}%
\repeat}\TY@save@row
\endarray\global\setbox1=\lastbox\setbox0=\vbox{\unvbox1
\unskip\global\setbox1=\lastbox}\egroup
\dimen@\TY@linewidth
\divide\dimen@\TY@count
\ifdim\dimen@<\tymin
\TY@warn{tymin too large (\the\tymin), resetting to \the\dimen@}%
\tymin\dimen@
\fi
\setbox\tw@=\hbox{\unhbox\@ne
\loop
\@tempdima=\lastskip
\ifdim\@tempdima>\z@
\global\advance\TY@linewidth-\@tempdima
\fi
\unskip
\setbox\tw@=\lastbox
\ifhbox\tw@
\ifdim\wd\tw@>\tymax
\wd\tw@\tymax
\fi
\TY@width\dimen@
\advance\dimen@\wd\tw@
\TY@width\xdef{\the\dimen@}%
\ifdim\dimen@<\tymin
\global\advance\TY@linewidth-\dimen@
\expandafter\xdef\csname TY@F\the\TY@count\endcsname
{\the\dimen@}%
\else
\expandafter\ifx\csname TY@F\the\TY@count\endcsname\z@
\global\advance\TY@linewidth-\dimen@
\expandafter\xdef\csname TY@F\the\TY@count\endcsname
{\the\dimen@}%
\else
\global\advance\TY@tablewidth\dimen@
\global\expandafter\let\csname TY@F\the\TY@count\endcsname
\maxdimen
\fi\fi
\advance\TY@count\m@ne
\repeat}%
\TY@checkmin
\TY@checkmin
\TY@checkmin
\TY@checkmin
\TY@count\z@
\let\TY@box\TY@box@v
\TY@ckpt
{\expandafter\TY@final\the\toks@\endTY@final}%
\count@\z@
\@tempswatrue
\@whilesw\if@tempswa\fi{%
\advance\count@\@ne
\expandafter\ifx\csname TY@SF\the\count@\endcsname\relax
\@tempswafalse
\else
\global\expandafter\let\csname TY@F\the\count@\expandafter\endcsname
\csname TY@SF\the\count@\endcsname
\global\expandafter\let\csname TY@\the\count@\expandafter\endcsname
\csname TY@S\the\count@\endcsname
\fi}%
\TY@linewidth\@ovxx
\TY@tablewidth\@ovyy
\ifnum0=`{\fi}}
\newcommand{\sidenote}[1]
{%
\stepcounter{localsidenotecounter}%
${}^\textrm{\footnotesize\arabic{localsidenotecounter}}$%
\immediate\write\tempfile%
{(\arabic{localsidenotecounter}) #1
}%
}
\newcommand{\sidenotepc}[1]
{
\noindent \begin{tabulary}{\textwidth}{>{\setlength\parindent{\normalparindent}
\ifx\@classz\TY@classz
\immediate\openout\tempfile=sidenotes.tex \fi}J<{\immediate\closeout\tempfile}@{\hspace{\colspace}}>{
\footnotesize \input{sidenotes.tex}
}J}
#1 & \end{tabulary}
}
\makeatother
\begin{document}
\sidenotepc{
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue\sidenote{Test} pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure\sidenote{Test} him some great pleasure\sidenote{Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure}.
}
\sidenotepc{
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue\sidenote{Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure} pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure\sidenote{Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure}
}
\end{document}
It turns out that I had an outdated version of babel
in my Library
folder (/Users/username/Library/texmf/tex/latex/babel/
). After deleting this outdated version, LaTeX used the correct, updated version found in the 2013 distribution (/usr/local/texlive/2013/texmf-dist/tex/latex/generic/babel/
). Documents now compile correctly!
Best Answer
You misquote the error message in your title. It is not
\end{tabulary}
that is undefined.The first two errors in your document are
So the first is a simple typo
\midule
is undefined and should be\midrule
.The second says that
\LT@save@row
is undefined, which is an internallongtable
command which latex tried to execute as part of\endhead
which is only defined forlongtable
.