I am trying to write a file using the document class file provided by the journal Semantics and Pragmatics at http://info.semprag.org/style. However, I can't even compile the example template they provide… Whenever I try to run LaTeX
on it, I get the following error:
ERROR: Undefined control sequence.
--- TeX said ---
./sp.cls:107:
Undefined control sequence.
<recently read> \DeclareUnicodeCharacter
l.107 \DeclareUnicodeCharacter
{2011}{\mbox{-}\nobreak\hskip0pt}
I tried both with auctex
and on overleaf.com but the error remained the same.
- The "empty template": http://info.semprag.org/examples/sp-template.tex
- The document class file: https://raw.githubusercontent.com/semprag/tex/master/sp.cls
Strangely, I couldn't find anything related to "undefined control sequence" error caused by \DeclareUnicodeCharacter
by Googling. This doesn't make sense to me since apparently the TeX engines just think \DeclareUnicodeCharacter
isn't a valid command at all, while the document class file as well as various examples on the Internet just use this command directly without any issue. Is there something wrong with the document class file when used with the newest version of TeX engine, or did I misconfigure something?
EDIT: The compile log: https://www.dropbox.com/s/49mkenzngua0we0/sp-template.log?dl=0
Best Answer
The macro
\DeclareUnicodeCharacter
is defined in the packageinputenc
when loaded with theutf8
encoding. So normally you need the following line before you use\DeclareUnicodeCharacter
:In this case though, the
sp.cls
already contains the line\RequirePackage[utf8]{inputenc}
on line 103, before it uses\DeclareUnicodeCharacter
on line 107, so you should be able to compilesp-template.tex
withpdflatex
even without explicitly adding the line.However, if you compile with the
xelatex
orlualatex
engines (which are Unicode-based and default toutf8
), then theinputenc
package gets ignored, and (only) a warning is printed in the error log:(Note the line that starts with "Package inputenc warning". IMO it makes sense for this to be an error instead, but probably the authors of
inputenc
chose to make it a warning because many files written withinputenc
have a chance of working on Unicode-based engines ifinputenc
simply does nothing.)So you need to either
if you wish to compile with XeTeX/LuaTeX, hack
sp.cls
to remove the following line:(note it was added to deal with a hyphenation problem which you are unlikely to have with a Unicode-based engine as presumably no one would define hyphenation after U+2011) and also these lines that use
\ifpdf
to mean “non-PostScript output” but unfortunately excludes XeTeX but not LuaTeX (they're ok to remove becausebreakurl
is not needed):(Note that if you're sending the source
.tex
file to someone else, such as the journal, then you shouldn't choose the latter option: and in general if you're submitting papers to journals you shouldn't mess with their style files. But if you're not going to send the file to anyone and are simply typesetting it in the journal's style for your own amusement, you can do whatever you like.)