# Tell LaTeX to use one command in one situation, a different one in another

In French, we write century numbers as the century number in Roman numerals, small caps, followed by e in superscript. As I use this a lot, I have created a command for it:

\newcommand{\siecle}[1]{\textsc{#1}\textsuperscript{e} siècle}


But, if I use this in titles or in bold fonts, the small caps don't work, and the letters of the century end up in lowercase. I have found a workaround for this, by looking around on here. I use the anyfontsize package to reduce the size of real capital letters to 9.2 points (between \footnotesize and \scriptsize).

I know this is not a nice solution, but it works, and is the only way I have found to do it, as shown here:

\documentclass[12pt,a4paper]{article}

\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{polyglossia}
\usepackage{anyfontsize}
\setmainlanguage{french}

\newcommand{\siecle}[1]{\textsc{#1}\textsuperscript{e} siècle}

\begin{document}

On est au \siecle{vii} av. J.-C.

On est au {\fontsize{9.2}{11}\selectfont  VII}\textsuperscript{e} siècle av. J.-C.

\textbf{On est au \siecle{vii} av. J.-C.}

\textbf{On est au {\fontsize{9.2}{11}\selectfont  VII}\textsuperscript{e} siècle av. J.-C.}

\end{document}


gives:

Would there be any way to create a command written in such a way that small caps are used if the font has them, but capitals reduced to a smaller font are used if it does not?

• Welcome to TeX.SE.
– Mico
Feb 13 '20 at 15:41

The Latin Modern fonts don't sport boldface small caps.

Use a font that does.

\documentclass[12pt,a4paper]{article}

\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{french}

\setmainfont{CMU Serif}

\newcommand{\siecle}[1]{\textsc{#1}\textsuperscript{e}~siècle} % <-- don't forget ~

\begin{document}

On est au \siecle{vii} av. J.-C.

On est au {\fontsize{9.2}{11}\selectfont  VII}\textsuperscript{e} siècle av. J.-C.

\textbf{On est au \siecle{vii} av. J.-C.}

\textbf{On est au {\fontsize{9.2}{11}\selectfont  VII}\textsuperscript{e} siècle av. J.-C.}

\end{document}


The proper answer is to choose a font-set with a bold small caps face included! You seem to be using latin modern which does not, but there are other derivatives of computer modern that do. On the other hand, I find xelatex (you should have mentioned that) to be very slow setting up a font like

\setmainfont[
UprightFeatures={SmallCapsFont=AlegreyaSC-Regular},
ItalicFeatures={SmallCapsFont=AlegreyaSC-Italic},
BoldFeatures={SmallCapsFont=AlegreyaSC-Bold},
BoldItalicFeatures={SmallCapsFont=AlegreyaSC-BoldItalic},
Ligatures=TeX,
]{Alegreya}


So here's your answer for the fake small-caps with a LaTeX macro. Use this \mysc in place of \textsc:

\makeatletter
\newcommand\mysc[1]{\leavevmode{%
\begingroup \def\X@a{bx}\edef\X@b{\f@series}%
\expandafter\endgroup
\ifx\x@a\x@b % missing bold small-caps
\dimen@\f@size\p@ \dimen@0.777\dimen@
\fontsize{\strip@pt\dimen@}{\f@baselineskip}%
\def\f@shape{n}%
\selectfont
\MakeUppercase{#1}%
\else
\scshape #1%
\fi
}}
\makeatother


Note that it leaves out some of the details in \textsc, like dealing with math.