1

I'm using the memoir class I'm trying to customise the appearance of lower-level headings. In one case, what I want to accomplish is very simple: adding a period at the end of a heading title (for example, to emulate what amsart does for \subsection). I want the period to be added only to the displayed heading in the document, not in table of contents: that is a reason why I'm not willing to add the period manually at the end of each heading text.

I haven't found a way to do this using the functionality provided by the memoir class neither in the memoir guide nor searching the Internet. In fact, I believe the latest memoir guide implicitly states this is not possible. Section 6.6 reads:

The lower level heads — sections down to subparagraphs — are also configurable, but there is nothing corresponding to chapter styles. There are essentially three things that may be adjusted for these heads: (a) the vertical distance between the baseline of the text above the heading to the baseline of the title text, (b) the indentation of the heading from the left hand margin, and (c) the style (font) used for the heading title.

The most common (class-agnostic) way to deal with this kind of customizations in LaTeX is using the titlesec package but I've often read that titlesec is somewhat incompatible with memoir. I went through the memoir guide, though, and I couldn't find an incompatibility statement. On the contrary, the introduction to the eight edition states:

The class also provides functions similar to those provided by the following packages, although the commands are different: crop, fancyhdr, geometry, sidecap, subfigure, titlesec. You can use these packages if you wish, or just use the capabilities of the memoir class.

Which is the right way to do what this kind of customisations when using memoir? Are memoir and titlesec now compatible? If it they are, is it safe to mix memoir heading customisations (e.g.: \setsecheadstyle, \setaftersubsecskip) with titlesec's or should I stick with titlesec if I use it?

lockstep
  • 250,273
  • 1
    You have written a lot of text, so much that i didn't even read it. Can you provide a minimal example that puts the text into code? – Johannes_B Mar 22 '15 at 13:19
  • @Johannes_B, the essence of my question is "Is there a memoir-specific way to customise the appearance of the text of a lower level heads?" If I had working code for this one, I'd have answered my own question. I put a lot of text to cite the relevant information I have, especially because a lot of people say that titlesec is "incompatible" with memoir, and titlesec seems to be the only package people cite when solving this problem. – Enrico M. Crisostomo Mar 22 '15 at 13:37
  • Thanks @AlanMunn. I had seen this one during my search, and it exemplifies why I'd rather not use a package that breaks the functionality of the memoir class. However, I'm OK with it if that's the only side effect of using titlesec with memoir but I wasn't sure about it (hence, my question). Thank you! – Enrico M. Crisostomo Mar 22 '15 at 13:46
  • Do you har have a macro that adds a period if none us present? As far as I remember, the setsecheadstyle and friends allow you to specify as the last macro, a macro that takes one argument. For example \MakeUppercase. So you can do it that way. If you use titlesec then that package takes over and none of the memoir specific setting will be used (again as far as I know) – daleif Mar 22 '15 at 15:52
  • But if you are also using hyperref you will probably get in to all sorts of trouble – daleif Mar 22 '15 at 15:53
  • @daleif At least a simple version of an add punctuation macro will not work correctly: e.g. \def\addpunc#1{#1.} \setsubsecheadstyle{\addpunc} puts the dot on the next line. – Alan Munn Mar 22 '15 at 17:36
  • Not at a computer, will look at it tomorrow. – daleif Mar 22 '15 at 17:59
  • If your title fits on one line, \newcommand{\addpunc}[1]{\mbox{#1.}} keeps the dot where it belongs. This seems to work OK with \hyperref. – alephzero Mar 22 '15 at 22:57
  • @AlanMunn, my memory was wrong, it is the toc configurations you can do this with. \section etc is made using \@startsection, and memoirs version of that is more or less using the kernel components, so one may need to hack some kernel components. – daleif Mar 23 '15 at 08:19
  • Hmm, did not save in time, you will need to hack \M@sect – daleif Mar 23 '15 at 08:32
  • @AlanMunn, and this part explains why you get a line break in that test #6{\@hangfrom{\hskip #3\relax\@svsec} \interlinepenalty \@M #9\@@par}, here #6 is the contents of the \setsecheadstyle (or what ever) – daleif Mar 23 '15 at 08:34
  • Thank you very much @daleif and sorry for the belated answer. I'm going to try your macro tonight. – Enrico M. Crisostomo Mar 24 '15 at 21:15

1 Answers1

1

This might work. Not tested with hyperref!

Basically we dissect the memoir source code and use etoolbox to patch the macro. Note however, this does not include \section* and friends, that has to be done slightly differently, and omitted here.

\documentclass[a4paper]{memoir}
\usepackage{etoolbox}
\makeatletter
% adapted from from amsthm
\def\MY@addpunct#1{%
  \relax\ifhmode
    \ifnum\spacefactor>\@m \else#1\fi
  \fi}

\patchcmd{\M@sect}{\@M#9\@@par}{\@M#9\MY@addpunct{.}\@@par}{
  \typeout{\string\M@sect\space patched (1)}
}{
  \typeout{\string\M@sect\space not patched (1)}
}
\patchcmd{\M@sect}{\@svsec #9}{\@svsec#9\MY@addpunct{.}}{
  \typeout{\string\M@sect\space patched (2)}
}{
  \typeout{\string\M@sect\space not patched (2)}
}
\makeatother


\begin{document}

\section{test}

\end{document}
daleif
  • 54,450