AMS alignments are executed twice internally, a first pass to measure the fields and a second pass to typeset. \label
is given a null definition the second time to avoid duplicating writes to the aux file which would generate errors.
So you do a global let of the real definition but you don't see it as you globally let to the null definition on the second pass.
You can see this by putting \show\mylabel
inside your multline
and see it reporting two values. You can use the \ifmeasuring@
switch to test which pass you are on. and just do the let on one of them.
\documentclass{minimal}
\usepackage{amsmath}
\begin{document}
\makeatletter
\begin{multline}
\ifmeasuring@
\global\let\mylabel\label
\show\mylabel
\fi
\end{multline}
\show\mylabel
\end{document}
Produces
> \mylabel=macro:
#1->\begingroup \measuring@false \label@in@display {#1}\endgroup .
l.14 \show\mylabel
There is a primitive \global
that makes a following TeX assignment global. So you can use \global\setbox
and \global\def
= \gdef
. In LaTeX as David Carlisle kindly points out you may get away with \global\setlength
in some circumstances, but in general it is not guaranteed to work, and loading packages such as calc
in fact prevents it working. One work around is to use an intermediate global TeX assignment of the result of a calculation via \global\len=\len
after the \setlength
:
\documentclass[a4paper]{article}
\usepackage{calc}
\newlength{\mylength}
\newlength{\myglength}
\newlength{\myllength}
\begin{document}
\setlength{\mylength}{10pt}
\setlength{\myglength}{10pt}
\setlength{\myllength}{10pt}
\verb+\mylength+ is \the\mylength.
\verb+\myglength+ is \the\myglength.
\verb+\myllength+ is \the\myllength.
\bigskip
\begin{minipage}{0.9\linewidth}
\setlength{\mylength}{20pt}
\setlength{\myglength}{20pt}
\global\setlength{\myllength}{20pt} % Doesn't work when calc is loaded
\global\myglength=\myglength
Minipage start
\verb+\mylength+ is \the\mylength.
\verb+\myglength+ is \the\myglength.
\verb+\myllength+ is \the\myllength.
Minigage end
\end{minipage}
\bigskip
\verb+\mylength+ is \the\mylength.
\verb+\myglength+ is \the\myglength.
\verb+\myllength+ is \the\myllength.
\end{document}
In the specific example you now give, you need to get hold of the totalheight
of the box, to get a picture of the same height and this then needs to be shifted down by the depth
of the minipage. The above \global
tricks will now work:
\documentclass{article}
\usepackage{calc}
\usepackage{picture}
\usepackage{ragged2e}
\newsavebox{\questiontextbox}
\newsavebox{\questionpicturebox}
\newlength{\questiontexttotalheight}
\newlength{\questiontextdepth}
\newenvironment{questiontext}[1]%
{\begin{lrbox}{\questiontextbox}%
\begin{minipage}[t]{#1}}%
{\end{minipage}\end{lrbox}%
\noindent\usebox{\questiontextbox}%
\settototalheight{\questiontexttotalheight}{\usebox{\questiontextbox}}%
\settodepth{\questiontextdepth}{\usebox{\questiontextbox}}%
\global\questiontexttotalheight=\questiontexttotalheight
\global\questiontextdepth=\questiontextdepth}
\newenvironment{questionpicture}[1]%
{\begin{lrbox}{\questionpicturebox}%
\setlength{\unitlength}{1cm}%
\begin{picture}(#1-\fboxsep-\fboxsep-0.8pt,\questiontexttotalheight)}%
{\end{picture}\end{lrbox}%
\fbox{\raisebox{-\questiontextdepth}{\usebox{\questionpicturebox}}}}
\begin{document}
\begin{questiontext}{0.2\columnwidth}
\RaggedRight There must be some text here so I made it up to fill more than just
a single line.
\end{questiontext}%
\begin{questionpicture}{0.8\columnwidth}
\put(0.5,0.5){\circle{0.4}}
\end{questionpicture}
\end{document}
I have changed a couple of extra things in your code. Firstly, the width of your \fbox
has not only the \fboxsep
but two rules 0.4pt
wide, so you need to substract 0.8pt
more to avoid an overfull box. Secondly, the narrow column on the left is better set ragged right, using the ragged2e
package provides the \RaggedRight
command which is less drastic than standard \raggedright
.
Best Answer
That is by design and coded accordantly in the LaTeX core source code. Counters in LaTeX usually count things which are independent from the local group. For example
figure
captions are enclosed in the group added by thefigure
environment and any change to thefigure
counter used by the caption would be lost afterwards. This would render the counter mostly useless.If you want to set a counter locally use
\c@<counter name>=value
. To add something to it use\advance\c@<counter name> by value
. To build the counter macro you can use\csname name\endcsname
or (mis-)use\value{name}
which also works on the left hand side of an assignment.You can also define an own counter using the TeX macro
\newcount\yourcounter
and then use\yourcounter=<value>
etc. However, you then need to define the\theyourcounter
macro yourself if you need it and can't use the normal counter formating macros like\arabic{..}
or\roman{..}
with it.