2

I want sections in subappendices to be numbered using lowercase small caps in memoir. That is, I want all references to these sections to use lowercase small caps. From the top of my head, this includes:

  1. The section heading \section{An appendix\label{an_appendix}}
  2. References to the section \ref{an_appendix}
  3. Entries in the table of contents
  4. Floats within the section
  5. References to floats within the section

There is probably more that I can't think of.

I suspect that this would best be fixed by changing the section counter used inside memoir's subappendices environment. But I can't figure out how to do it.

In the MWE below, I have commented out some partial partial fixes, which handle (1) section heading numbers, (3) float caption number, and (4) TOC numbers.

I would prefer a clean solution that changes the counter for subappendix sections (or something even cleaner that I can't see), but would settle for fixing the references.

What should I be doing instead?

\documentclass{memoir}
\usepackage{amsmath}
\usepackage{fontspec}
\setmainfont{EBGaramond-Regular}[
  BoldFont = EBGaramond-Bold,
  ItalicFont = EBGaramond-Italic,
  BoldItalicFont = EBGaramond-BoldItalic,
  Numbers={Proportional, OldStyle},
]
\AtBeginEnvironment{subappendices}{
  \numberwithin{table}{section}
}
\setsecnumformat{\textsc{\csname the#1\endcsname}\quad}
% \setsecnumformat{\textsc{\MakeLowercase{\csname the#1\endcsname}}\quad} % (1) Make numbers in section headings lowercase small caps
\usepackage{caption}
\DeclareCaptionLabelFormat{lowercase}{\MakeLowercase{#1}~#2}
% \DeclareCaptionLabelFormat{lowercase}{\MakeLowercase{#1~#2} % (3) Make numbers in float captions lowercase small caps
\captionsetup{
  labelfont=sc,
  labelformat=lowercase,
}
% \makeatletter % (4) Make numbers in the table of contents lowercase small caps
% \patchcmd\numberline{\@cftbsnum #1\@cftasnum}{\@cftbsnum{#1}\@cftasnum}{}{\ERROR}
% \makeatother
% \renewcommand\cftsectionpresnum{\scshape\MakeLowercase}
\begin{document}
  \tableofcontents*

  \chapter{A chapter}
  \section{A section}
  See table~\ref{tab:a_table} in appendix~\ref{an_appendix}.

  \begin{subappendices}
    \section{An appendix\label{an_appendix}}
    \begin{table}[h]
      \caption{A table\protect\label{tab:a_table}}
      \centering
      \begin{tabular}{lcc}
        & Column A & Column B \\
        First row & 123 & 456 \\
        Second row & 123 & 456 \\
      \end{tabular}
    \end{table}
  \end{subappendices}
\end{document}

Output with added red rectangles around unwanted features

6
  • Unrelated, but your code gives an error. Add a \protect here: \caption{A table\protect\label{tab:a_table}} Apr 19 at 12:04
  • @Iacobus1983 Strange. For me, it compiles just fine. But, on the other hand, your \protect doesn't change anything. So I'll add it.
    – Fredrik P
    Apr 19 at 12:09
  • Do you mind cleaning the question and explaining what the end goal instead of the long text at the start. As I see it there are two problems correct? The section numberring and the table numbering?
    – daleif
    Apr 19 at 12:27
  • @daleif Exactly. But as you already answered, I guess there is no point in making the question snappier...?
    – Fredrik P
    Apr 19 at 12:43
  • It would help users coming by in the future to better understnad what you were actually asking for,
    – daleif
    Apr 19 at 13:20

1 Answer 1

3

Both can be solved using a single line

\renewcommand{\setthesection}{\thechapter.\alph{section}}

At the start of subappendices we run this command

\newcommand{\@resets@ppsub}{
  \par
  \setcounter{section}{0}
  \renewcommand{\thesection}{\setthesection}
  \def\theHsection{\theHchapter.\Alph{section}}
}

with

\newcommand{\setthesection}{\thechapter.\Alph{section}}

so it is enough to mess with that.

The toc is then fixed using the outcommented

\renewcommand\cftsectionpresnum{\scshape\MakeLowercase}

This solves the reference stuff. It works with hyperref as well. If there are some package that adds an optional arg to \ref, then that needs to be picked up as well. Still wondering if there is a hook cone can use instead.

\AtBeginDocument{
  \NewCommandCopy\oldref\ref
  \RenewDocumentCommand\ref{sm}{%
    \textsc{%
      \IfBooleanTF{#1}%
      {\oldref*{#2}}%
      {\oldref{#2}}%
    }%
  }
}
6
  • That's great! But the references are now just lowercase. But I guess that should be an easy fix. For example, an ugly fix would be \let\oldref\ref and \renewcommand{\ref}[1]{\textsc{\oldref{#1}}}.
    – Fredrik P
    Apr 19 at 12:37
  • 1
    @FredrikP be very careful with redefining \ref, there you are loosing functionality as \ref actually takes an optional * these days.
    – daleif
    Apr 19 at 13:29
  • 1
    The references actually was listed as a requirement (I wrote that I "would settle for fixing the references"), but, as you rightly pointed out, the original question was a bit convoluted/bloated. And thanks for informing me about \ref
    – Fredrik P
    Apr 19 at 13:40
  • 1
    @FredrikP I've asked in chat whether there is a hook one can used to change the font of all references. One cannot use the obvious \AddToHook{cmd/ref/before}{\scshape} as there is no grouping, so all the text ends up as small caps.
    – daleif
    Apr 19 at 13:43
  • 2
    you could try \renewcommand{\setthesection}{\thechapter.\textsc{\alph{section}}}. Apr 19 at 14:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .