[Tex/LaTex] How to check if a document is “oneside” or “twoside”

double-sidedkoma-script

In my document I've a side capture environment as well as a full width environment for figures and tables. In the past I all my documents were printed on the back and front of a page, thus I had a clause in the environment that checked if a page is odd or even.

Now I want to only print on one side of the page and thus the environment should check for that. How can I accomplish this? (I'm using scrbook).

    \documentclass[a4paper, oneside]{scrbook}    
...
    \usepackage{realboxes}
        \newenvironment{fwfigure}[1][htbp]%
        {%
            \begin{figure}[#1]
                \checkoddpage
                \edef\side{\ifoddpage l\else r\fi}% <<<--- Here should another if statement check the *side-mode
                \Makebox[\textwidth][\side]\bgroup%
                \begin{minipage}[t]{\textwidth+\marginparsep+\marginparwidth}
                    \centering
                }{%
            \end{minipage}%
            \egroup%
        \end{figure}
    }

EDIT:

I ended up doing this:

\makeatletter
    \if@twoside%
        \newcommand{\side}{\ifoddpage l\else r\fi} %% twoside=true
    \else%
        \newcommand{\side}{l} %% twoside=false
    \fi%
\makeatother
%%%

\usepackage{realboxes}
\newenvironment{fwfigure}[1][htbp]%
{%
    \begin{figure}[#1]
        \checkoddpage
        \Makebox[\textwidth][\side]\bgroup%
        \begin{minipage}[t]{\textwidth+\marginparsep+\marginparwidth}
            \centering
        }{%
    \end{minipage}%
    \egroup%
\end{figure}
}

Best Answer

The test is provided by the LaTeX kernel with

\newif \if@twoside     \@twosidefalse

So you can use this test. Please note that the test string uses @ so you need \makeatletter / \makeatother (See: What do \makeatletter and \makeatother do?)

Edit

There is a great answer of David explaining the how \newif command works

As mention by egreg the package \typearea which is loaded by every KOMA-Class by default provides the option twoside=semi. In this case the condition above should be extended by \if@semitwoside.

However based on your example you can redefine your environment as follows:

\makeatletter
%preamble
\if@twoside%
   %%% put the stuff for true here (twoside=true)
   \newcommand\side{stuff for twoside}
\else%
   %%% put the stuff for false here (twoside=false)
   \newcommand\side{stuff for onside}
\fi%  
\makeatother

\newenvironment{fwfigure}[1][htbp]%
 {%
   \figure[#1]
     \side 
   \endfigure%
}