I'm writing a class, and when using it I want to use small caps with a font that doesn't have small caps defined (I know – not as good as the real thing). I found this answer Fake small caps with XeTeX/fontspec? which I tried to include, however I get the errors:
Missing $ inserted.
Missing $ inserted.
You can't use '\spacefactor' in vertical mode.
However, the code works perfectly when it's pasted into the preamble.
Anyone know what's going on?
MWE
Class File
\ProvidesClass{custom}[a custom class]
\NeedsTeXFormat{LaTeX2e}
\DeclareOption*{
\PassOptionsToClass{\CurrentOption}{scrreprt}
}
\ProcessOptions\relax
\LoadClass[usegeometry]{scrreprt}
\RequirePackage{graphicx}
\RequirePackage{plex-serif}
% Small Caps
\makeatletter
\newlength\fake@f
\newlength\fake@c
\def\fakesc#1{%
\begingroup%
\xdef\fake@name{\csname\curr@fontshape/\f@size\endcsname}%
\fontsize{\fontdimen8\fake@name}{\baselineskip}\selectfont%
\uppercase{#1}%
\endgroup%
}
\makeatother
\newcommand\fauxsc[1]{\fauxschelper#1 \relax\relax}
\def\fauxschelper#1 #2\relax{%
\fauxschelphelp#1\relax\relax%
\if\relax#2\relax\else\ \fauxschelper#2\relax\fi%
}
\def\Hscale{.83}\def\Vscale{.72}\def\Cscale{1.00}
\def\fauxschelphelp#1#2\relax{%
\ifnum`#1>``\ifnum`#1<`\{\scalebox{\Hscale}[\Vscale]{\uppercase{#1}}\else%
\scalebox{\Cscale}[1]{#1}\fi\else\scalebox{\Cscale}[1]{#1}\fi%
\ifx\relax#2\relax\else\fauxschelphelp#2\relax\fi}
\makeatletter
\newcommand{\maketitleee}{
\fauxsc{\@title}
}
\makeatother
Document
\documentclass[a4paper, 12pt, oneside]{custom}
\title{Title}
\author{Author}
\begin{document}
\maketitleee
\end{document}
Update
Removing all the \makeatletters and \makeatothers seems to change the errors given to those below
Update 2
This was fixed by @moewe's suggestion, which is replacing \fauxsc{\@title} with \expandafter\fauxsc\expandafter{\@title}


\documentclasscommand, have a minimal preamble and then\begin{document}...\end{document}. The code should compile and be as small as possible to demonstrate your problem. Cutting your code down to a MWE may well reveal what your problem actually is. In any case, it is really difficult to help you without more information. – Nov 13 '18 at 07:10$inserted' errors, but the 'You can't use '\spacefactor' in vertical mode.' comes up when you try to use or (re-)define a command name beginning with@without using\makeatletter...\makeatother, see https://tex.stackexchange.com/q/8351/35864 (note how the answer in the linked question has\makeatletter...\makeatotheraround all commands with@in their names). Class files and.styfiles are automatically processed with\makeatletteron, which would explain why a command can be defined and used there, but not in the document. – moewe Nov 13 '18 at 07:10\LoadClass{article}call at the beginning to load the basic LaTeX commands defined in the base classes – siracusa Nov 13 '18 at 07:38\maketitleeeshould have the\makeatletter/\makeatotheroutside, not inside. There might be other problems (code looks complicated). – Nov 13 '18 at 08:28.cls) you should not have to use\makeatletterand\makeatotherat all - remove them. – moewe Nov 13 '18 at 08:31\makeatletterand\makeatother. – egreg Nov 13 '18 at 08:33\makeatletterand\makeatotherthe macro doesn't work. Moving them outside did change the errors I was getting though, and now they won't go away even if I move that bit into the preamble. Seems likefakescdoesn't like being surrounded by\makeatletterand\makeatother. – tecosaur Nov 13 '18 at 08:39\makeatletter...\makeatothers (both pairs) and change to a different font (I don't have Plex installed), the MWE compiles fine without errors, the output also seems to be as expected. If you get an error or different problems when you remove the\makeat...s, please update your question accordingly. – moewe Nov 13 '18 at 08:45\makeatletterand a\makeatotherin your.clsfile. Remove all\makeatletters and\makeatothers from the.cls. As I said before if I remove all of them (in the earlier version two pairs, now only one pair), the MWE compiles. – moewe Nov 13 '18 at 08:52\fauxscaround the\@title. The implementation of\fauxscseems to impose conditions on its argument, try\expandafter\fauxsc\expandafter{\@title}instead. – moewe Nov 13 '18 at 09:51