% cr-formatting-setup-local.tex  
% CircuitousRoot LaTeX Formatting, 2023 Reworking, 
% Locally modifiable "setup" macros.
% Revision 1, 2023-01-03
%
% Copyright 2023 by Dr. David M. MacMillan.
% License:  LaTeX Project Public License Version 1.3c.
%           This work has the LPPL maintenance status 'unmaintained'.
%           This work consists of the files:
%           "cr-formatting-preamble-local.texfrag",
%           "cr-formatting-preamble.texfrag",
%           "cr-formatting-setup.texfrag", and
%           "cr-formatting-setup.texfrag".
%           See:  http://www.latex-project.org/lppl/
%           Note:  This work is described in a document,
%                  "cr-formatting-guide.tex" (CircuitousRoot LaTeX Formatting),
%                  which is licensed under the 
%                  Creative Commons Attribution 4.0 International license.

% Encoding:  UTF-8, Unicode
% Requires:  XeLaTeX (xelatex)

% Usage:
% This is a fragment of a TeX/LaTeX file.  It is intended to provide
% the second portion of the setup for the CircuitousRoot LaTeX 
% formatting (2022 reworking).
% To use it, first cp it to a local file.
% Then \input it as the second thing after your document begins:
%
% \begin{document}
% \input{cr-formatting-setup.texfrag}
% \input{cr-formatting-setup-MYDOCUMENT.texfrag}
%
% Modify these macros to select specific aspects of the house style
% for your document (e.g., book, monograph, or article).
% You can also put any local (to your document) macros here.
%
% You should also have copied and modified 
% "cr-formatting-preamble-local.texfrag" and \input it and
% "cr-formatting-preamble.texfrag" as the
% first non-comment statements of your LaTeX document:
%
%    \input{cr-formatting-preamble-mylocaldocument.texfrag}
%    \input{cr-formatting-preamble.texfrag}
%
% For complete usage notes, see the document "CircuitousRoot LaTeX Formatting,"
% which should have accompanied these macros.
%------------------------------------------------------------------------------


% Headings, using the titlesec package.
%--------------------------------------

% titlesec calls \sectionbreak automatically.
\newcommand{\sectionbreak}{\clearpage}

% Space before and after headings.
% titlesec puts extra space before chapters; remove it 
% (-20pt is an empirical value which seems to work)

\titlespacing\chapter{0pt}%                         flush left
                     {-20pt plus 0pt minus 0pt}   %  = 0pt, really
                     {12pt plus 0pt minus 0pt}    %  0pt w/out glue below

\titlespacing\section{0pt}%                         flush left
                     {18pt plus 0pt minus 0pt}%     18pt w/out glue above
                     {0pt plus 0pt minus 0pt}    %  0pt w/out glue below
\titlespacing\subsection{0pt}%                         flush left
                     {14pt plus 0pt minus 0pt}%     14pt w/out glue above
                     {0pt plus 0pt minus 0pt}    %  0pt w/out glue below
\titlespacing\subsubsection{0pt}%                         flush left
                     {14pt plus 0pt minus 0pt}%     14pt w/out glue above
                     {0pt plus 0pt minus 0pt}    %  0pt w/out glue below

% Heading formats.
\titleformat{\chapter}
  {\normalfont\sffamily\fontsize{18pt}{16pt}\bfseries}
% Note:  Previously I used U+25C6, which is a black diamond.
%        TeX Gyre Pagella supports only U+2666, which is a black diamond suit
%        Gillius ADF No. 2 does not support either
%  {\thechapter{\hskip1.5pt\raisebox{2pt}{\fontsize{8pt}{8pt}\selectfont\char"25C6}}}{6pt}{}      
%        So use U+25CA, an open lozenge, instead.  Make it bigger than U+25C6
  {\thechapter{\hskip1.5pt\raisebox{0pt}{\fontsize{18pt}{18pt}\selectfont\char"2022}}}{6pt}{}      

\titleformat{\section}
  {\normalfont\sffamily\fontsize{16pt}{16pt}\bfseries}
%  {\thesection{\hskip1.5pt\raisebox{2pt}{\fontsize{8pt}{8pt}\selectfont\char"25C6}}}{6pt}{}      
  {\thesection{\hskip1.5pt\raisebox{0pt}{\fontsize{16pt}{16pt}\selectfont\char"2022}}}{6pt}{}   



% Debugging
%----------

% Uncomment to get a margin vertical rule flagging overfull hboxes.
% Caution:  If the box is so wide as to be off of the page, this rule
%           will be invisible.
\overfullrule=5pt

% Boilerplate
\input{texts-mergenthaler-big-red-dwiggins.texfrag}


% Silencing overly verbose output
%--------------------------------
% TO DO:  Turn this into a more general command

% Helper command:  \crFirstWord
%From: 
%https://tex.stackexchange.com/questions/316730/extract-first-word-in-a-string
%Based on an example/query by dbmrq and a response by egreg, 
%both posted Jun 26, 2016 at 20:28
%
% This is the original example by dbmrq (which I can't get to work):
%\makeatletter
%\newcommand\FirstWord[1]{\@firstword#1 \@nil}%
%\newcommand\@firstword{}%
%\def\@firstword#1 #2\@nil{#1\unskip}%
%\makeatother
%
% Here is the solution to dbmrq's problem (his version failed to remove 
% a trailing comma) by egreg.  It works for me here, but is more than I need.
%\makeatletter
%\newcommand\crFirstWord[1]{\@firstword#1 \@nil}%
%\newcommand\@firstword{}%
%\newcommand\@removecomma{}%
%\def\@firstword#1 #2\@nil{\@removecomma#1,\@nil}%
%\def\@removecomma#1,#2\@nil{#1}
%\makeatother

\makeatletter
\newcommand\crFirstWord[1]{\@firstword#1 \@nil}%
\newcommand\@firstword{}%
\def\@firstword#1 #2\@nil{#1}%
\makeatother

% Modify \typeout to remove messages from package "contour".
% Remove all messages from package "contour" from output
\renewcommand{\typeout}[1]{%
   \ifthenelse{\equal{\crFirstWord{#1}}{contour:}}
   {}
   {\message{#1}}
}

% Remove "Missing character" messages...
% These come from xetex and cannot be removed in the LaTeX source.
% You can remove them by:
%   - turning off wordwrap
%   - then filtering the output through grep -v


