[Tugindia] Using conditionals

Nina Mazumdar nina.mazumdar at gmail.com
Sun Sep 14 16:59:32 CEST 2008

On Sun, Sep 14, 2008 at 4:19 PM, Kannan Moudgalya <kannan at iitb.ac.in> wrote:
> Nina Mazumdar wrote:
>>
>> On Sat, Sep 13, 2008 at 11:12 PM, Kannan Moudgalya <kannan at iitb.ac.in>
>> wrote:
>>> I want to know how to use the conditionals in LaTeX.  For example, if I
>>> have the \multicols option on, I want the width of the inserted figures
>>> to be \linewidth.  If this option is off, the width should become
>>> 0.5\linewidth.
>>>
>> Do we need to go for any conditional command? What we need is nothing
>> but a new dimension defined which is exactly the column width.
>>
>> Here is one way of doing it:
>
> Nina,
>
> Thanks for your mail.  The above solution will work if the same length (as a
> proportion of the column width) is to be used in one column and two column
> format.  In case the figure size is chosen not from aesthetic point of view,
> but some other optimality condition (e.g. document should fit in one page)
> one may want to change the size - conditionals will be useful then.
> To explain further, the question papers that I set typically fit into one
> page, if I use the two column format - I have attached one such paper.   I
> keep the questions and answers together, so that I can easily maintain them
> and reuse them, if necessary: a \eatans command kills all the answers,
> \eatquest kills all the questions; if I comment out both, questions and
> answers come in the output.  Because answers often involve long expressions,
> I use the one column format when answers have to be compiled.  I may lose
> some aesthetics while preparing the questions, because of the requirement
> that the question paper should fit in one page.  I don't have page
> restrictions while preparing the answers.  At that time, I will be more
> concerned about aesthetics.  In other words, I may want to use different
> scaling factors for different figures.
>
> To cut the story short, I still need a solution that makes use of
> conditionals.  If I have this facility, for each figure, I will define the
> length for the two column mode and another for the single column format.

I'm sorry, your problem seems to be a bit hazy to me. If I have
understood correctly, you may still use the dimen register
\Columnwidth.  But you might want to recompute it everytime
\includegraphics is called depending upon the column mode.  If you use
the LaTeX's default column functionality, you already have a boolean,
\if at twocolumn.

\newdimen\Columnwidth
\def\computeFigWidth{%
\if at twocolumn
\Columnwidth=\linewidth % or whatever
\else
\Columnwidth=.5\linewidth % or whatever
\fi}
%
% Now we will call this in every \@Includegraphics macro:
%
\def\Includegraphics{\@ifnextchar[{\@Includegraphics}{\@Includegraphics[]}}
\def\@Includegraphics[#1]#2{\computeFigWidth
\includegraphics[#1,\Columnwidth]{#2}}

This will work only with default \@twocolumn mode in LaTeX.
Unfortunately the default two column does not balance columns at the
end.

If you want to use {multicols} environment of multicol packages, there
is no boolean available.  You need to define an environment yourself
which will call {multicol} with your defined boolean becoming true.
Maybe like the one following:

\let\savemulticols\multicols
\let\saveendmulticols\endmulticols
\newif\if at multicols \@multicolsfalse
\def\multicols{\global\@multicolstrue\savemulticols}
\def\endmulticols{\saveendmulticols\global\@multicolsfalse}

Now \computeFigWidth shall be modified as given below:

\def\computeFigWidth{%
\if at multicols
\Columnwidth=\linewidth % or whatever
\else
\Columnwidth=.5\linewidth % or whatever
\fi}