4

In order to fix a bug in the new version of the sidenotes package (bug reported here), I made the following environment:

\newenvironment{autoadjustwidth}[2]%
{\ifthenelse{\boolean{@twoside}}%
{\begin{adjustwidth*}{#1}{#2}}%
{\begin{adjustwidth}{#1}{#2}}%
}%
{\ifthenelse{\boolean{@twoside}}%
{\end{adjustwidth*}}%
{\end{adjustwidth}}%
}%

The autoadjustwidth environment tries to distinguish between book/twopage/symmetric and article/'all pages similar' styles. Can I rely on @twoside to detect this?

Full MWE for one particular case, where a figure fills the textcolumn plus the margin:

%\documentclass{article}
\documentclass{book}

\usepackage{lipsum}
\usepackage{ifthen}
\usepackage{changepage}
\usepackage{mwe}
\usepackage{graphicx}

\makeatletter
\newlength{\overhang}
\setlength{\overhang}{\marginparwidth}
\addtolength{\overhang}{\marginparsep}

\newlength{\full}
\setlength{\full}{\textwidth}
\addtolength{\full}{\overhang}

\newenvironment{autoadjustwidth}[2]%
{\ifthenelse{\boolean{@twoside}}%
{\begin{adjustwidth*}{#1}{#2}}%
{\begin{adjustwidth}{#1}{#2}}%
}%
{\ifthenelse{\boolean{@twoside}}%
{\end{adjustwidth*}}%
{\end{adjustwidth}}%
}%
\makeatother

\renewenvironment{figure*}[1][htbp]{%
\begin{figure}[#1]%
\begin{autoadjustwidth}{}{-\overhang}}%
{\end{autoadjustwidth}%
\end{figure}}%

\begin{document}
\lipsum[1]
\begin{figure*}
\includegraphics[width=\full, height=100pt]{example-image-a}
\end{figure*}
\lipsum[3]
\newpage
\lipsum[1]
\begin{figure*}
\includegraphics[width=\full, height=100pt]{example-image-a}
\end{figure*}
\lipsum[3]
\end{document}
Andy
  • 6,269

1 Answers1

6

@twoside is exactly the boolean to detect whether the document is two sided or not. It is part of the latex kernel. If you load etoolbox then you can test it with \ifbool:

\makeatletter
\newenvironment{autoadjustwidth}[2]%
{\ifbool{@twoside}%
{\begin{adjustwidth*}{#1}{#2}}%
{\begin{adjustwidth}{#1}{#2}}%
}%
{\ifbool{@twoside}%
{\end{adjustwidth*}}%
{\end{adjustwidth}}%
}%
\makeatother

Note that the scr classes have an extra option of setting twoside=semi. This results in a mixed typesetting scheme with some two sided features but where margin notes are always placed on the same side. This value is tested with \ifbool{@semitwoside. The twoside=semi option results in \@twosidetrue and \@semitwosidetrue; twoside or twoside=true gives \@twosidetrue and \@semitwosidefalse; oneside or twoside=false gives \@twosidefalse and \@semitwosidefalse.

Andrew Swann
  • 95,762