5

I'm trying to switch to the ntheorem package (instead of amsthm) but I realized that headers of the theorems aren't protruded: Whatever.

\documentclass{article}
\usepackage[activate={true, nocompatibility}, factor=2000]{microtype}
\usepackage{ntheorem}
\usepackage[showframe]{geometry}

\makeatletter
\newtheoremstyle{mystyle}
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ (##3)\theorem@separator]}
\makeatother

\theoremstyle{mystyle}
\theorembodyfont{\upshape}
\theoremseparator{.}
\newtheorem{what}{Whatever}

\begin{document}
    \noindent\bfseries Whatever.\normalfont

    \begin{what}
        Something here.\newline
        Whatever.
    \end{what}
\end{document}

I've tried this and \theorem@headerfont\protrudeleft{##1} makes protrusion correct - but also it generates a few errors and affects formatting of the theorem. So how should I fix it? Thank you in advance for help.

  • 2
    The ntheorem package has implemented the headers of theorem-like structures as "list items" -- in the LaTeX jargon sense of the word. Short of using the \protrudeleft hack, microtype has no way of "knowing" that some left-kerning should be applied to the character W in Whatever. This is true even if \labelsep were set to 0pt and the directive \hskip\labelsep were omitted entirely from the setup code. If you feel strongly enough about this issue, you may want to contact the maintainer(s) of the ntheorem package and ask for a re-write of major parts of the package's code... – Mico Dec 28 '17 at 20:04
  • @Mico, I was wondering if I can define a command, let's say \protrusionAmount, which returns a protrusion value of a given character. Then I think it's possible to fix this issue: define new length, let's say \modLabelsep, which equals to \labelsep minus \protrusionAmount{W} and use \hskip\modLabelsep instead of \hskip\labelsep. But I don't know how to define \protrusionAmount. Moreover, I'm not sure if \protrusionAmount{W} is equal to \protrusionAmount{\itshape W} or \protrusionAmount{\bfseries W}. – Jakbog Dec 29 '17 at 13:08
4

The problem with the code you tried from the other answer is that here the unboxing takes place inside another (incompatible) box, which makes tex stumble. The solution is, just as you suggested in your comment, to measure the protrusion first and then subtract it from the label sep:

\documentclass{article}
\usepackage[activate={true, nocompatibility}, factor=2000]{microtype}
\usepackage{ntheorem}
\usepackage[showframe]{geometry}

\makeatletter
\makeatletter
\newcommand*\protrudeleft[1]{%
    {\everypar{}%
     \setbox\z@\vbox{\noindent#1}%
     \vbadness=\@M
     \splittopskip=\z@
     \global\setbox\z@=\vsplit\z@ to \baselineskip
     \unvbox\z@ \global\setbox\z@=\lastbox
    }%
    \@tempdima=\leftmarginkern\z@ 
}
\newtheoremstyle{mystyle}
{\protrudeleft{\theorem@headerfont ##1}%% measure left margin kern
 \item[\hskip\dimexpr\labelsep+\@tempdima %% add to labelsep
 \theorem@headerfont ##1\ ##2\theorem@separator]}
{\protrudeleft{\theorem@headerfont ##1}%
 \item[\hskip\dimexpr\labelsep+\@tempdima 
 \theorem@headerfont ##1\ ##2\ (##3)\theorem@separator]}
\makeatother

\theoremstyle{mystyle}
\theorembodyfont{\upshape}
\theoremseparator{.}
\newtheorem{what}{Whatever}

\begin{document}
    \noindent\bfseries Whatever.\normalfont

    \begin{what}
        Something here.\newline
        Whatever.
    \end{what}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.