%%% Things we need to do if producing final layout

% amsthm breaks \@for
\let\forloop\@for

\RequirePackage{ifthen}            % For definition of: \ruledsec
                                   % Moved from Sec 1 by RZ

%
%%
%%% 1. Inclusion of additional packages =======================================
%%
%

\let\oldpageref=\pageref

% Bibliography styles

\RequirePackage{natbib}            % For cite commands

% This allows for hyphenation of German words with umlauts
\RequirePackage[T1]{fontenc}

% Other packages:

\usepackage{fourier} % Utopia as Math font; fourier 
\RequirePackage{bodoni12gillsans}  % Bodoni12 and GillSans as default rm and sf
\RequirePackage{multicol}          % For two column text

%
%%
%%% 2. Page layout ============================================================
%%
%

%
%% a) Dimensions and lengths --------------------------------------------------
%

%%% Set size of trimmed page {height}{width}{ratio}:

\settrimmedsize{234mm}{153mm}{*}
%\settrimmedsize{9in}{6.5in}{*} % Changed 2016.11.08 ds

%%% Set size of type block {textheight}{textwidth}{ratio}:

\settypeblocksize{190mm}{114mm}{*} % Changed 2016.11.08 ds
%\settypeblocksize{44pc}{28pc}{*} % Grandits (6/07/05): 45pc

%% Set spine margin {spine}{edge}{ratio}:

\setlrmargins{1in}{*}{*}

%% Set upper margin (trimtop to textbox)

\setulmargins{17.5mm}{*}{*} % Measured from CBH book.

%%% Set distances of header and footer:

\setheaderspaces{32pt}{*}{*}

%\setheadfoot{\onelineskip}{3\onelineskip}
% Footnotes are defined below.

%%% Set size of margin notes:
%\setmarginnotes{17pt}{51pt}{\onelineskip}

%%% Positioning of trimmed page on stock:

% Set top of trimmed edge 1in from top of stock:

\setlength{\trimtop}{1in}

% Center page horizontally on stock:

\setlength{\trimedge}{\stockwidth}
\addtolength{\trimedge}{-\paperwidth}
\setlength{\trimedge}{.5\trimedge} 

\checkandfixthelayout

%% Set paragraph indentation

\setlength{\parindent}{20pt}

%
%% b) Title page --------------------------------------------------------------
%

% Parameters: Title, subtitle, author/editor information, extra info.

\newcommand{\titlepage}[4]{%
{% Begin local environment for title page. For: \parindent

\setlength{\parindent}{0pt}
\cleardoublepage\thispagestyle{empty}

%%%% Title box
\parbox[b][168pt]{\linewidth}{% was: 130pt
\BodoniFortyeight
#1
\BodoniThirty 
#2
}% End Title box
\vspace{4.5pt} %was: 12pt
\longrule
\vspace{12pt}
%%%% Author box
  \parbox[b]{\linewidth}{\GillSansEightteen\raggedright% for CWRC (RZ)
    #3\phantom{p}} % End Author box
\vspace{4pt} \longrule
%%%% Extra box
\par\vspace{25pt}\noindent
\parbox[t][100pt]{\linewidth}
{\GillSansFourteen\raggedright
{}%
#4}%
%%%% Publisher
\vfill
\leavevmode\par
%\hspace{8pt}
\includegraphicscn[height=1cm]{../sty/oup-logo.pdf}\par
%\vspace{5pt}
%{\logonamefont Oxford University Press}\par
%\vspace{5pt}
%{\logoaddrfont Oxford}%
}% End local environment for titlepage

\newpage
}

\newcommand{\bastardtitle}{%
\chapter* {\bastardtitlefont The Collected Works of Rudolf Carnap}%
%\vskip 14pt
\noindent {\bastardsubtitlefont Volume \cwrcvolume}
\thispagestyle{empty}}


%
%%
%%% 3. Chapter and section formatting =========================================
%%
%

%
%% a) Numbering ---------------------------------------------------------------
%

\setcounter{secnumdepth}{4} % numbering depth for sections

%-1 -> empty
% 0 -> chapters
% 1 -> sections
% 2 -> subsections
% 3 -> subsubsections

%
%% b) Chapters ----------------------------------------------------------------
%

%% Define command for long rule under chapter headings

\newlength{\extendline} 
\setlength{\extendline}{\textwidth}
\addtolength{\extendline}{\oddsidemargin} % Exact length to margin
\addtolength{\extendline}{.125in}         % plus 1/8 inch

\newcommand{\longrule}{\hrule height 2pt width \extendline\relax}

%% Set chapter number (to be used before \chapter command)

\newcommand{\setchapternumber}[1]{%
\setcounter{chapter}{#1}\addtocounter{chapter}{-1}}


%% Defined and set global lengths (to be used in chapter styles)

\newlength{\chapterbox}\setlength{\chapterbox}{38mm} % was 41mm
\newlength{\chapterbeforeline}\setlength{\chapterbeforeline}{0pt}
\newlength{\chapterafterline}\setlength{\chapterafterline}{9pt}

%% Chapterstyle: unnumbered ----------

\makechapterstyle{unnumbered}{%
\renewcommand{\printchaptertitle}[1]{% From Guldo K, comp.text.tex
  \parbox[b][\chapterbox]{\linewidth}{\chaptitlefont ##1}%
\newline%
\longrule
\vspace{\chapterafterline}
}

\setlength{\beforechapskip}{0pt}
\setlength{\midchapskip}{0pt}
\setlength{\afterchapskip}{26pt}

\renewcommand{\printchaptername}{}
\renewcommand{\printchapternum}{}
\renewcommand{\chapterheadstart}{}

% Chapter titles are set ragged right in
\renewcommand{\chaptitlefont}{\raggedright\chapterfont}

\renewcommand{\afterchaptertitle}{%
% \vspace{\chapterbeforeline}
% \longrule
%\par\nointerlineskip\vskip 5pt\relax\par
%\vspace{\chapterafterline}
}

\makeevenfoot{plain}{}{\footerfont \thepage}{} % Footer on chapter page
\makeoddfoot{plain}{}{\footerfont \thepage}{} % Footer on chapter page

\makeatletter
\renewcommand*\thesection {\@arabic\c@section} % Without chapter number
\makeatother

}% End of \makechapterstyle{unnumbered}

%% Chaptersytle: indexunnumbered ----------

\makechapterstyle{indexunnumbered}{%
\renewcommand{\printchaptertitle}[1]{% From Guldo K, comp.text.tex
  \parbox[b][\chapterbox]{\linewidth}{\chaptitlefont ##1}%
\newline%
}

\setlength{\beforechapskip}{0pt}
\setlength{\midchapskip}{0pt}
\setlength{\afterchapskip}{0pt}

\renewcommand{\printchaptername}{}
\renewcommand{\printchapternum}{}
\renewcommand{\chapterheadstart}{}

% Chapter titles are set ragged right in
\renewcommand{\chaptitlefont}{\raggedright\chapterfont}

\renewcommand{\afterchaptertitle}{%
\vspace{\chapterbeforeline}
\longrule
\par\nointerlineskip\vskip 5pt\relax\par
\vspace{\chapterafterline}
\vspace{1cm}} % ONLY DIFFERENCE TO unnumbered STYLE

\makeevenfoot{plain}{}{\footerfont \thepage}{} % Footer on chapter page
\makeoddfoot{plain}{}{\footerfont \thepage}{} % Footer on chapter page

\makeatletter
\renewcommand*\thesection {\@arabic\c@section} % Without chapter number
\makeatother

}% End of \makechapterstyle{indexunnumbered}

%% Chaptersytle: numbered ----------

% Use of parbox, thanks to Guldo K, comp.text.tex

\makechapterstyle{numbered}{%
\makeatletter
\renewcommand{\printchaptertitle}[1]{% 
\ifthenelse{\boolean{strchp}}{% Starred version of chapter command
  \parbox[b][\chapterbox]{\linewidth}{\chaptitlefont ##1}%
\newline}{% Unstarred version of chapter command
  \parbox[b][\chapterbox]{\linewidth}{{\chapnamefont \@chapapp~\thechapter}\par
\vspace{\baselineskip}\chaptitlefont ##1}%
\newline}% End of \ifthenelse
}% End of \printchaptertitle
\makeatother

\setlength{\beforechapskip}{0pt}
\setlength{\midchapskip}{0pt}
\setlength{\afterchapskip}{0pt}

\renewcommand{\printchaptername}{}
\renewcommand{\printchapternum}{}
\renewcommand{\chapterheadstart}{}

\renewcommand{\chapnamefont}{\chapterfont}

% Chapter titles are set ragged right
\renewcommand{\chaptitlefont}{\raggedright\chapterfont}

\renewcommand{\afterchaptertitle}{%
\vspace{\chapterbeforeline}
\longrule
\par\nointerlineskip\vskip 5pt\relax\par
\vspace{\chapterafterline}}

\makeevenfoot{plain}{}{\footerfont \thepage}{} % Footer on chapter page
\makeoddfoot{plain}{}{\footerfont \thepage}{} % Footer on chapter page

\renewcommand*\thesection{\thechapter.\@arabic\c@section} % With ch number

}% End of \makechapterstyle{numbered}

%% Chapter author

% \newlength{\afterchapauthor}

% RZ - make author raggedright like title
\newcommand{\chapterauthor}[1]{%
\markright{#1}%
\parbox[t][20mm]{\textwidth}{\raggedright\authorfont #1}%
% To see size of parbox, put \fbox around it.
}

% RZ - for when you don't want a byline under the chapter heading
\newcommand*{\nochapterauthor}{\vspace{1cm}}


%% Chapters on even pages --------------

% Define command for long rule under chapter headings

\newlength{\extension}
\setlength{\extension}{\oddsidemargin}
\addtolength{\extension}{.125in}

%\newlength{\extendline} 
\setlength{\extendline}{\textwidth}
\addtolength{\extendline}{\extension}
%\addtolength{\extendline}{\oddsidemargin} % Exact length to margin
%\addtolength{\extendline}{.125in}         % plus 1/8 inch
\newcommand{\longVrule}{\vrule height 2pt width \extendline\relax}

\newcommand{\chapteronverso}{% Change position of line under heading
\renewcommand{\afterchaptertitle}{%
\vspace{\chapterbeforeline}
\hspace{-\extension}\raise -2pt \hbox{\longVrule}
\par\nointerlineskip\vskip 5pt\relax\par
\vspace{\chapterafterline}}%
}

\newcommand{\chapteronrecto}{% Default
\renewcommand{\afterchaptertitle}{%
\vspace{\chapterbeforeline}
\longrule
\par\nointerlineskip\vskip 5pt\relax\par
\vspace{\chapterafterline}}%
}

%% c) Sectioning----------------------------------------------------------------
%

% \secnumdot and \secnumnodot for formatting section numbers with or
% without trailing period

\newcommand*{\secnumdot}{\setsecnumformat{\csname the##1\endcsname.\quad}}
\newcommand*{\secnumnodot}{\setsecnumformat{\csname the##1\endcsname\quad}}

%% headstyles for formatting headings

%% Section numbers without chapter number

%% headstyle main for editorial material and items that are not books

\makeheadstyles{main}{
  \chapterstyle{unnumbered}
  \setbeforesecskip{-4.5ex plus -1ex minus -.2ex} % Original: -3.5ex
  \setsecheadstyle{\sectionfont\raggedright}
  \setsubsecheadstyle{\GillSansTwelveTwelve\raggedright}
  \setbeforesubsecskip{-3.25ex \@plus -1ex \@minus -.2ex}
  \setaftersubsecskip{1.5ex \@plus .2ex}
  \setsubsubsecheadstyle{\sffamily\itshape\raggedright}%
  \setbeforesubsubsecskip{-3.25ex \@plus -1ex \@minus -.2ex}%
  \setaftersubsubsecskip{1.5ex \@plus .2ex}
  \setparaheadstyle{\sffamily}
  \setafterparaskip{-1em}
}

% \chaptersec to typeset \section hedings like chapters (without line
% underneath)

\newcommand{\chaptersec}[1]{\vspace*{50pt}\vspace*{\topskip}{\chaptitlefont #1}}

% headstyle book for an item that is a book

\makeheadstyles{book}{
  \chapterstyle{unnumbered}
  \setsechook{\clearpage\thispagestyle{chapter}}
  \setsecheadstyle{\chaptersec}
  \setaftersecskip{26pt}

  \setbeforesubsecskip{-4.5ex plus -1ex minus -.2ex} % Original: -3.5ex
  \setsubsecheadstyle{\sectionfont\raggedright}
  \setsubsubsecheadstyle{\GillSansTwelveTwelve\raggedright}
  \setbeforesubsubsecskip{-3.25ex \@plus -1ex \@minus -.2ex}
  \setaftersubsubsecskip{1.5ex \@plus .2ex}
  % \setsubsubsecheadstyle{\sffamily\itshape\raggedright}%
  % \setbeforesubsubsecskip{-3.25ex \@plus -1ex \@minus -.2ex}%
  % \setaftersubsubsecskip{1.5ex \@plus .2ex}
  \setparaheadstyle{\sffamily}
  \setafterparaskip{-1em}
}

%
%% g) Table of contents -------------------------------------------------------
%

%% Set text for ToC headings

\renewcommand{\tocmark}{\markboth{\contentsname}{\contentsname}}

%% Commands for writing in the table of contents

% Disable default toc entries
\setcounter{tocdepth}{-1} % -1 stands for no entries

\newcommand{\tocchapter}[1]{%
  \addtocontents{toc}{\bigskip\noindent{\Large #1}\par}}
\newcommand{\tocchapterpage}[1]{%
  \addtocontents{toc}{\bigskip\noindent{\Large #1\hfill\thepage}\par}}

% RZ - Make author raggedright in toc, with same right margin as chapter title
\newcommand{\tocauthor}[1]{%
  \addtocontents{toc}{\protect\nobreak\noindent\rightskip\protect\@tocrmarg {}#1\par}}
\newcommand{\tocauthorpage}[1]{%
  \addtocontents{toc}{\protect\nobreak\noindent\rightskip\protect\@tocrmarg {}#1\hfill{\Large\thepage}\par}}

% Disable Full Circle toc commands: for chapters and authors
\newcommand{\notocchaptercommands}{% 
  \renewcommand{\tocchapter}[1]{}
  \renewcommand{\tocchapterpage}[1]{}}

\newcommand{\notocauthorcommands}{% 
  \renewcommand{\tocauthor}[1]{}
  \renewcommand{\tocauthorpage}[1]{}}

% No numbering of chapters in toc
\renewcommand{\chapternumberline}[1]{}

% Set width of page numbers in toc
\setpnumwidth{3em}
\setrmarg{3.5em plus1fil} % RZ - titles ragged right (from tocloft.dtx)

% Set font of chapters in toc
\renewcommand{\cftchapterfont}{\normalfont\Large}
\renewcommand{\cftchapterpagefont}{\normalfont\Large}
\renewcommand{\cftchapterindent}{0pt}
\renewcommand{\cftchapternumwidth}{0pt}

% Sections in toc: no dots, spacing, . after section number

\renewcommand{\cftsectiondotsep}{\cftnodots}
\cftsetindents{section}{1em}{2em} % Indent, numwidth
\renewcommand{\cftsectionaftersnum}{.}
\setlength{\cftbeforesectionskip}{1ex}

% Subsections in toc: no dots, spacing, . after section number

\renewcommand{\cftsubsectiondotsep}{\cftnodots}
\cftsetindents{subsection}{2em}{3em} % Indent, numwidth
\renewcommand{\cftsubsectionaftersnum}{.}

%
%%
%%% 4. Commands for font selection ============================================
%%
%

% Default font families (can be changed using \useComputerModernFont)

\newcommand{\ibxfamily}{\fontencoding{T1}\fontfamily{ibx}}
\newcommand{\ibdfamily}{\fontencoding{T1}\fontfamily{ibd}} % \rmdefault
\newcommand{\ibyfamily}{\fontencoding{T1}\fontfamily{iby}}

% Global labels (these are to be used in the new command definitions!)

% The code after the command corresponds to the code in the
% Typographic Spec Sheet (10/13/04)

\newcommand{\chapterfont}{\GillSansEightteenEightteen} % CH
\newcommand{\authorfont}{\GillSansFourteenEightteen}  % CA

% CWRC has larger sections
\newcommand{\sectionfont}{\GillSansFourteen}
% FullCircle section font
% \newcommand{\sectionfont}{\GillSansTwelveTwelve}

\newcommand{\footerfont}{\GillSansTen}
\newcommand{\headerfont}{\GillSansNine}

\newcommand{\introductionfont}{\GillSansTen} % (facing pages intro)

\newcommand{\footnotefont}{\BodoniEight} % FTN
\newcommand{\epigraphfont}{\BodoniNine}

\newcommand{\logonamefont}{\BodoniFourteenEightteen}
\newcommand{\logoaddrfont}{\BodoniTwelveFourteen}

% CWRC Bastard Title & Subtitle
\newcommand{\bastardtitlefont}{\BodoniEightteen} %
\newcommand{\bastardsubtitlefont}{\GillSansEightteen}

\newcommand{\indexfont}{\BodoniNineEleven}

%

\newcommand{\useComputerModernFont}{%
  \renewcommand*{\rmdefault}{cmr} % Select Computer Modern as rm default
  \renewcommand\sfdefault{phv}    % Select Helvetica as sf default
  \renewcommand{\ibxfamily}{\rmfamily}
  \renewcommand{\ibyfamily}{\rmfamily}
}

% GillSans 
% (mgs is selected as sfdefault in bodoni12gillsans.sty)

%\renewcommand\sfdefault{phv}  % Select Helvetica as sf default
%\renewcommand\sfdefault{mgs}  % Select GillSans as sf default

%\newcommand{\GillSans}[1]{\textsf{\Huge #1}}

\newcommand{\GillSansNine}{\sffamily\small}
\newcommand{\GillSansTen}{\sffamily\normalsize}
\newcommand{\GillSansTwelve}{\sffamily\large}
\newcommand{\GillSansElevenFourteen}{\sffamily\fontsize{11}{14pt}\selectfont}
\newcommand{\GillSansTwelveTwelve}{\sffamily\fontsize{12}{12pt}\selectfont}
\newcommand{\GillSansThirteen}{\sffamily\fontsize{13}{15pt}\selectfont}
\newcommand{\GillSansFourteen}{\sffamily\fontsize{14}{16pt}\selectfont}
%\sffamily\Large}
\newcommand{\GillSansFourteenEightteen}{\sffamily\fontsize{14}{18pt}\selectfont}
\newcommand{\GillSansSixteen}{\sffamily\fontsize{16}{20pt}\selectfont}
\newcommand{\GillSansEightteen}{\sffamily\fontsize{18}{20pt}\selectfont}
\newcommand{\GillSansEightteenEightteen}{\sffamily\fontsize{18}{18pt}\selectfont}
%\LARGE}

% Bodoni Six

\newcommand{\BodoniEight}{\ibxfamily\fontsize{8}{9pt}\selectfont}

% Bodoni Twelve (\rmdefault is \ibdfamily)

\newcommand{\BodoniEightTen}{\rmfamily\fontsize{8}{10pt}\selectfont}
\newcommand{\BodoniNine}{\rmfamily\fontsize{9}{10pt}\selectfont}
\newcommand{\BodoniNineEleven}{\rmfamily\fontsize{9}{11pt}\selectfont}
\newcommand{\BodoniThirteen}{\rmfamily\fontsize{13}{15pt}\selectfont} % Eds
%\newcommand{\BodoniFourteen}{\rmfamily\fontsize{14}{16pt}\selectfont}

% Bodoni Seventytwo

\newcommand{\BodoniTwelveFourteen}{%
\ibyfamily\fontsize{12}{14pt}\selectfont} % For logo on titlepage

\newcommand{\BodoniFourteenEightteen}{%
\ibyfamily\fontsize{14}{18pt}\selectfont} % For logo on titlepage

\newcommand{\BodoniEightteen}{%
\ibyfamily\fontsize{18}{18pt}\selectfont} % For subtitle on bastard title

\newcommand{\BodoniFortyeight}{\ibyfamily\fontsize{48}{48pt}\selectfont}

\newcommand{\BodoniThirty}{\ibyfamily\fontsize{30}{34pt}\selectfont}

% For compatibility reasons (do not use!)
\newcommand{\BdFourteen}{\rmfamily\Large}
\newcommand{\BdFortyeight}{\ibyfamily\fontsize{48}{48pt}\selectfont}
\newcommand{\BdThirty}{\ibyfamily\fontsize{30}{34pt}\selectfont}

% Put a file called "nofonts" in your main CWRC folder if you don't
% have Gill Sans and Bodoni installed
\IfFileExists{../nofonts}{\useComputerModernFont}{}

%
%% 
%%% 5. Footnotes ==============================================================
%%
%

%
%% a) Appearance of default footnotes -----------------------------------------
%

% \pagefootnoterule, \mpfootnoterule, and \splitfootnoterule
% are provided by \RequirePackage[splitfootnotes]{footmisc}
% For split footnote, see CBH, 268

% Lengths regarding footnotes
% - the following three are defined in memoir, but overwritten by footmisc!

\setlength{\footmarkwidth}{0pt} % Set footnote indentation to 0pt
\setlength{\footmarksep}{0pt}   % Set footnote indentation to 0pt
\setlength{\footparindent}{0pt} % Set paragraph indentation to 0pt

% DS 2016.11.08: Change the line below does not seem to make any difference...
 \setlength{\skip\footins}{12pt} % Set distance bw. main text and footnotes

% Footnote text

\renewcommand{\foottextfont}{\footnotefont}%\footnotesize}

% Marker
% - the following is defined in memoir, but overwritten by footmisc!

\footmarkstyle{#1.\ }
%\renewcommand{\footnoterule}{}
% Hint from c.t.t. 2007/09/24:
% \setfootnoterule[\vfill]{3pt}{0.4\columnwidth}{\normalrulethickness} 
\setfootnoterule[\vfill]{3pt}{0pt}{0pt} 

%
%%
%%% 6. Header and footer ======================================================
%%
%

% See TLC2, 218-219 for \markboth

%% Pagestyle: collection (e.g., "Carnap Brought Home") ----------

% Header of even pages: pagenumber ... chapter author (if one is defined)
% Header on odd pages:  [Optional] Chapter title ... pagenumber

\makepagestyle{collection}

\makeheadposition{collection}{flushright}{flushleft}{}{}
\makeevenhead{collection}{\headerfont\thepage}{}{\headerfont\rightmark}{}
\makeoddhead{collection}{\headerfont\leftmark}{}{\headerfont\thepage}{}
\makepsmarks{collection}{%
 \renewcommand{\chaptermark}[1]{\markboth{##1}{}}
 \renewcommand{\sectionmark}[1]{}
}
% Note: need the ##1 instead of #1
% Alternatively: \def\chaptermark##1{\markboth{##1}{}}
% Alternatively: \def\sectionmark##1{}

%% Pagestyle: chapsec ----------

% Header of even pages: pagenumber   ..  . chapter title
% Header on odd pages:  current section title ... pagenumber

\makepagestyle{chapsec}

\makeheadposition{chapsec}{flushright}{flushleft}{}{}
\makeevenhead{chapsec}{\headerfont\thepage}{}{\headerfont\leftmark}{}
\makeoddhead{chapsec}{\headerfont\rightmark}{}{\headerfont\thepage}{}
\makepsmarks{chapsec}{%
 \renewcommand{\chaptermark}[1]{\markboth{##1}{}}
 \renewcommand{\sectionmark}[1]{\markright{##1}}
}

%% Generic commands ----------

\newcommand{\headerleft}[1]{\markboth{#1}{}}
\newcommand{\headerright}[1]{\markright{#1}}

%
%%
%%% 7. Bibliography commands ==================================================
%%
%

% No point between author and year (5th nonopt. parameter)
% See: natnotes.dvi

\bibpunct[, ]{(}{)}{;}{a}{}{;}    % natbib

% Set length of hanging of bibliography entries

\setlength{\bibhang}{\parindent}  % natbib was: {1.5\parindent}

% Set vertical spacing between bibliography entries

\setlength{\bibsep}{\itemsep} % \itemsep (natbib) or 0pt

% To change font of bibliography  use
% \newcommand{\bibfont}{\indexfont} % natbib

%
%%
%%% 8. Two column mode ========================================================
%%
%

\newcommand{\startTwoColumns}{\begin{multicols}{2}}
\newcommand{\finishTwoColumns}{\end{multicols}}

%
%%
%%% 9. Facing pages mode ======================================================
%%
%

%
%% a) Sectioning commands -----------------------------------------------------
%

% This command continues the current line and then breaks the page.
%   Use this to adjust the pages of the facing English translation.

\newcommand{\cutpageline}{\vadjust{\newpage}}

% This command ends a page directly where the command occurs.
%   Should be used only rarely, since it can introduce excessive spacing
%   between words.
%\raggedbottom\renewcommand{\cutpage}{\pagebreak}

\def\cutpagehere{{\parfillskip0pt\relax\par}\newpage\noindent}

% The following commands are for breaking up an introduction so that
% it covers only the upper part of facing pages (see maintext.tex)

\newcommand{\cutintro}{{\parfillskip0pt\relax\par}}
\newcommand{\introlineright}{\par\hfill\rule{.5\textwidth}{.4pt}\par}
\newcommand{\introlineleft}{\par\noindent\rule{.5\textwidth}{.4pt}\par}
\newcommand{\introline}{\par\noindent\hfill\rule{.5\textwidth}{.4pt}\hfill\hbox{}\par}


%
%% b) Page numbering ----------------------------------------------------------
%

% Based upon: changepagenumbering.sty (Version 1.0, 9/24/05, Dirk Schlimm)

% Provides commands:
%
% \incrementpagebyone
% \incrementpagebytwo

% Save \@outputpage macro

%\makeatletter
\let\mytempoutputpage\@outputpage

% Change page numbering to double counting

\newcommand{\incrementpagebytwo}{\g@addto@macro\@outputpage{\stepcounter{page}}}

% Reset page numbering 

\newcommand{\incrementpagebyone}{\let\@outputpage\mytempoutputpage}
%\makeatother

%
%%
%%% 10. Multilingual support ==================================================
%%
%

% Language switches (courtesy of Bernd Buldt)

\newcommand{\slE}{\selectlanguage{english}}
\newcommand{\slG}{\selectlanguage{german}}
\newcommand{\slF}{\selectlanguage{french}}

\newcommand{\slGE}[1]{\slG{#1}\slE}
\newcommand{\slFE}[1]{\slF{#1}\slE}

\newcommand{\slEG}[1]{\slE{#1}\slG}

%
%%
%%% 11. Index =================================================================
%%
%

% Use \renewcommand{\indexname}{NewName} in the document to change the
% name of the index.

\makeindex % Generate .idx file. This must be converted into an .ind file
           % by makeindex. The index is printed in the text with \printindex

% Write index into table of contents and set space before index entries
\renewcommand{\preindexhook}{\nochapterauthor} %\vspace{\afterchapauthor}}

%\showindexmarktrue % List index arguments in the margin of the text.

\onecolindexfalse % Two column index (default)
\indexintoc       % Index entry in table of contents (default)

% Set gutter between the two index columns
\setlength{\indexcolsep}{2pc} 

%% From memoir.cls (with changes!)

% Complete redefinition. 2017.08.29 ds
\makeatletter
\renewenvironment{theindex}{%
  \if@twocolumn
    \@restonecolfalse
  \else
    \@restonecoltrue
  \fi
    \cleardoublepage
    \chapterstyle{indexunnumbered}% Added by ds
    \setlength{\columnsep}{\indexcolsep} % Must be here! ds
    % \twocolumn[\@makeschapterhead{\indexname}
    %           \preindexhook]%
    \twocolumn
    \chapter{\indexname}
  \thispagestyle{chapter}
  \parindent\z@
  \parskip\z@ \@plus .3\p@\relax
  \let\item\@idxitem}
  {\if@restonecol\onecolumn\else\twocolumn\fi}
\makeatother

%
%%
%%% 12. Additional environments ===============================================
%%
%

%
%% a) Quote/quotation ---------------------------------------------------------
%

\renewenvironment{quote}%
{\begin{list}{}
  {\setlength{\leftmargin}{\parindent}
   \setlength{\rightmargin}{\parindent}
   \setlength{\topsep}{6pt}}
  \raggedyright\item\relax} % RZ - changed to raggedyright for less raggedness
{\end{list}}

\makeatletter
\renewenvironment{quotation}%
{\begin{list}{}
  {\setlength{\leftmargin}{\parindent}%
   \setlength{\rightmargin}{\parindent}%
   \setlength{\topsep}{6pt}%
   \setlength{\listparindent}{1.5em}%
   \setlength{\itemindent}{1.5em}%
   \setlength{\parsep}{\z@ \@plus\p@}\raggedyright}% RZ - changed to raggedyright for less raggedness
   \item\relax}
{\end{list}}
\makeatother

%
%% b) Epigraph ----------------------------------------------------------------
%

\setlength{\epigraphwidth}{.5\textwidth} % No rule between text and source
\setlength{\epigraphrule}{0pt} % No rule between text and source
\epigraphfontsize{\epigraphfont}

% Text is set by default ragged right.

% Use \textit{...} or \itshape to change shape to italics (this is not
% done by default, otherwise the source would be by default in
% italics, too).

%------------------------------------------------------------------------------

% =======================================
% End copied material from fullcircle.sty

\usepackage{facingpages}
\usepackage{microtype}
%\usepackage[generic,psscale]{mathfont}
%\usepackage[italic]{mathastext}
\usepackage{soul} % for letter spacing

%%% CWRC page styles

% Added this style for chapter title pages. DS 2017.03.16
% (so far, only provisionally)
\makepagestyle{onlypagesheader}

\makeheadposition{onlypagesheader}{flushright}{flushleft}{}{}
\makeevenhead{onlypagesheader}{\headerfont\thepage}{}{}{}
\makeoddhead{onlypagesheader}{}{}{\headerfont\thepage}{}
\makepsmarks{onlypagesheader}{%
 \renewcommand{\chaptermark}[1]{}
 \renewcommand{\sectionmark}[1]{}
}


%% Pagestyle: original/translation ----------

% Page style for texts in original & translations
% Headers are set by the \texthead commands
% (original title on left/odd, translation title on right/even pages)
% chapter & section commands do not reset the running heads

\makepagestyle{original}

\makeheadposition{original}{flushright}{flushleft}{}{}
\makeevenhead{original}{\headerfont\thepage}{}{\headerfont\leftmark}{}
\makeoddhead{original}{\headerfont\rightmark}{}{\headerfont\thepage}{}
\makepsmarks{original}{%
 \renewcommand{\chaptermark}[1]{}
 \renewcommand{\sectionmark}[1]{}
}

\makepagestyle{translation}

\makeheadposition{translation}{flushright}{flushleft}{}{}
\makeevenhead{translation}{\headerfont\thepage}{}{\headerfont\leftmark}{}
\makeoddhead{translation}{\headerfont\rightmark}{}{\headerfont\thepage}{}
\makepsmarks{translation}{%
 \renewcommand{\chaptermark}[1]{}
 \renewcommand{\sectionmark}[1]{}
}

% pagestyle for an item that's a book already in english

% \section's are the books chapters and will set the running header on
% right/even pages to "#. title"

\makepagestyle{englishbook}

%\makeheadposition{englishbook}{flushright}{flushleft}{}{}
\makeevenhead{englishbook}{\headerfont\thepage}{}{\headerfont\leftmark}{}
\makeoddhead{englishbook}{\headerfont\rightmark}{}{\headerfont\thepage}{}
\makepsmarks{englishbook}{%
  % left header: book title right header: chapter
  \renewcommand{\chaptermark}[1]{}
  \renewcommand{\sectionmark}[1]{\markright{##1}}
}

% pagestyle notes -----
% for Information on text & editorial notes

\makepagestyle{notes}

\makeheadposition{notes}{flushright}{flushleft}{}{}
\makeoddhead{notes}{\headerfont\rightmark}{}{\headerfont\thepage}{}
\makeevenhead{notes}{\headerfont\thepage}{}{\headerfont\leftmark}{}
\makepsmarks{notes}{%
 \renewcommand{\chaptermark}[1]{}
 \renewcommand{\sectionmark}[1]{\markright{##1}}
}

% backmatter pagestyle
% \chapter sets both running heads (textual Notes, Index, Bibliography)

\makepagestyle{backmatter}

\makeheadposition{backmatter}{flushright}{flushleft}{}{}
\makeevenhead{backmatter}{\headerfont\thepage}{}{\headerfont\leftmark}{}
\makeoddhead{backmatter}{\headerfont\leftmark}{}{\headerfont\thepage}{}
\makepsmarks{backmatter}{%
 \renewcommand{\chaptermark}[1]{\markboth{##1}{##1}}
 \renewcommand{\sectionmark}[1]{}
}

% space after Bibliography chapter title
\renewcommand{\prebibhook}{\nochapterauthor}

\def\markhead#1#2#3{\markboth{#1 (#3)}{#2 (#3)}}
\def\englishmarkhead#1#2#3{\markboth{#2 (#3)}{}}

% Commands for typesetting the actual texts

% texthead - Makes a title page for a text on facing pages

\newcommand{\texthead}[4][]{\openright
\chapter{\textit{#4}\\ \foreignlanguage{german}{#2}}
\chapterauthor{#3}\tocauthor{#3}
\ifthenelse{\equal{#1}{}}{\markhead{\foreignlanguage{german}{#2}}{#3}{#4}}{\markhead#1{#4}}
\thispagestyle{onlypagesheader}% DS 2016.12.09
\openany}

% onlyenglishtexthead - Makes a title page for an English-only text

\newcommand{\onlyenglishtexthead}[3][]{\openright
\chapter{\textit{#3}\\ #2}
\nochapterauthor
\ifthenelse{\equal{#1}{}}{\markhead{#2}{#2}{#3}}{\markhead{#1}{#1}{#3}}
\openany}

% originaltext - sets up and loads the German text

\newcommand{\originaltext}[1]{\openany
\BeginFacingPagesLeft\selectlanguage{german}
\pagestyle{original}\restartfootnotenumbering
\fakeexnotes
\input{#1}}

% translationtext - sets up and loads the English text on rectos only

\newcommand{\translationtext}[1]{%
\BeginFacingPagesRight
\selectlanguage{english}
\pagestyle{translation}
\restartfootnotenumbering
\realexnotes
\IfFileExists{#1}{\input{#1}}{Not yet translated}\EndFacingPages}

% onlyenglishtext - sets up and loads the German text

\newcommand{\onlyenglishtext}[1]{%
\selectlanguage{english}
\pagestyle{translation}\restartfootnotenumbering
\realexnotes
\input{#1}}

% englishbook - sets up and loads the text of a book in English only

\newcommand{\englishbooktext}[1]{%
\selectlanguage{english}
\pagestyle{englishbook}
\headstyles{book}
\restartfootnotenumbering
\realexnotes
\input{#1}
\headstyles{main}
}

% textinclude - does everything for a text on facing pages optional
% argument sets running heads, left and right heads must be enclosed
% in {}

\newcommand*{\textinclude}[4][]{%
\texthead[#1]{#2}{#3}{#4}%
\settocdepth{chapter}
\originaltext{../#4/#4-de}
\translationtext{../#4/#4-en}
\clearpage
\pagestyle{notes}\settocdepth{section}
\ifthenelse{\equal{#1}{}}{\englishmarkhead{}{#3}{#4}}{\englishmarkhead#1{#4}}
\IfFileExists{../#4/#4-notes}{\input{../#4/#4-notes}}{%
  \pagenotehead
  \smallskip
  \printpagenotes*}
\clearpage}

% onlyenglishtextinclude - does everything for a text in English only; optional
% argument sets running heads

\newcommand*{\onlyenglishtextinclude}[3][]{%
\onlyenglishtexthead[#1]{#2}{#3}%
\settocdepth{chapter}
\onlyenglishtext{../#3/#3}
\clearpage
\pagestyle{notes}\settocdepth{section}
\IfFileExists{../#3/#3-notes}{\input{../#3/#3-notes}}{%
  \pagenotehead
  \smallskip
  \printpagenotes*}
\clearpage}

% englishbookinclude - does everything for a book in English only; optional
% argument sets running heads

\newcommand*{\englishbookinclude}[3][]{%
\onlyenglishtexthead[#1]{#2}{#3}%
\clearpage%
\settocdepth{subsection}%
\englishbooktext{../#3/#3}
\pagestyle{notes}
\IfFileExists{../#3/#3-notes}{\input{../#3/#3-notes}}{%
  \pagenotehead
  \smallskip
  \printpagenotes*}
\clearpage}


\RequirePackage{carnap}

% Don't print title and year in final copy

\renewcommand{\titleandyear}[4][]{}
\renewcommand{\titleandyeartrans}[3]{}

% don't print bibliography annotations

\renewcommand{\bibAnnote}[2]{}

% space lists tightly
\tightlists

% don't print notes section when we're doing final copy
\newcomment{notes}

\newcommand{\restartfootnotenumbering}{\setcounter{footnoteE}{0}
\setcounter{footnote}{0}
\setcounter{pagenote}{0}}

% highlight type, trans, and varnotes but don't print the notes in the text

\renewcommand*{\typonoteprint}[2]{{\color{green!70!black}#1}}
\renewcommand*{\transnoteprint}[2]{{\color{red!70!black}#1}}
\renewcommand*{\varnoteprint}[2]{{\color{green!70!black}#1}}
