7

I am trying to compile a long document and I got this error message:

Command \titlefont already defined

So, I've opened the .log file to understand what was happening. The lines around the eror message are these ones:

("C:\Program Files\MiKTeX 2.9\tex\latex\koma-script\scrlfile.sty"
Package: scrlfile 2017/09/07 v3.24 KOMA-Script package (loading files)
)))

LaTeX Warning: Command \@footnotemark  has changed.
           Check if current package is valid.


! LaTeX Error: Command \titlefont already defined.
           Or name \end... illegal, see p.192 of the manual.


See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.1225 \newcommand*\titlefont{\sectfont}
                                    %

So, it seemed to me that the scrlfile.sty contained a new definition of the \titlefont command. But it doesn't. As you can see, whatever file contains that new definition, it has it at the line 1225, whereas the file scrlfile.sty is only 492 lines long. So, my question is:

How can I determine which package is trying to redefine the \titlefont command?

Note: My LaTeX doesn't define the \titlesec command.

5
  • Maybe it's a predefined command. Try renewcommand instead. Jun 5, 2018 at 11:26
  • 1
    Possible duplicate of Where do I find out how a command/environment is defined? Jun 5, 2018 at 11:28
  • 5
    Can you please post an MWE? The preamble is important Jun 5, 2018 at 11:31
  • 1
    Note that the file scrlfile.sty has already been closed when the error occurs (look at the closing parentheses). A class that defines a \titlefont command is, for example, scrbook.
    – GuM
    Jun 5, 2018 at 11:32
  • You can add \errorcontextlines 5 to your preamble to get more context.
    – user4686
    Jun 5, 2018 at 12:19

2 Answers 2

8

As per which packages/classes define \titlefont, a non exhaustive search may include

$ pushd /usr/local/texlive/2018/texmf-dist/tex/latex/

$ grep -r '\\newcommand.*\\titlefont'
achemso/achemso.cls:\newcommand*\titlefont{\bfseries\sffamily}
curve/curve.cls:\newcommand\titlefont[1]{\gdef\@titlefont{#1}}
disser/disser.cls:  \newcommand\titlefont{\Large\bfseries}
koma-script/scrartcl.cls:\newcommand*\titlefont{\sectfont}%
koma-script/scrartcl.cls:\newcommand*{\scr@fnt@title}{\titlefont}%
koma-script/scrbook.cls:\newcommand*\titlefont{\sectfont}%
koma-script/scrbook.cls:\newcommand*{\scr@fnt@title}{\titlefont}%
koma-script/scrextend.sty:\newcommand*\titlefont{\sectfont}%
koma-script/scrextend.sty:\newcommand*{\scr@fnt@title}{\titlefont}%
koma-script/scrreprt.cls:\newcommand*\titlefont{\sectfont}%
koma-script/scrreprt.cls:\newcommand*{\scr@fnt@title}{\titlefont}%
moderncv/moderncv.cls:\newcommand*{\titlefont}{}
moderncv/moderncv.cls:\newcommand*{\titlestyle}[1]{{\titlefont#1}}
qcm/qcm.cls:\newcommand\titlefont[1]{\gdef\@titlefont{#1}}
simplecv/simplecv.cls:\newcommand{\titlefont}[1]{\def\cv@tit@fnt{#1}}

$ grep -r '\\def\\titlefont'
dialogl/listout.tex:\def\titlefont{bold}
dialogl/listout.tex:\def\titlefontsize{10}
dialogl/listout.tex:\def\titlefont{bold}
dialogl/listout.tex:\def\titlefontsize{10}
disser/autoref.rtx:\def\titlefont{\normalsize}
disser/bachelor.rtx:\def\titlefont{\Large\bfseries}
disser/candidate.rtx:\def\titlefont{\normalsize}
disser/doctor.rtx:\def\titlefont{\normalsize}
disser/master.rtx:\def\titlefont{\Large\bfseries}
disser/specialist.rtx:\def\titlefont{\Large\bfseries}
ifmslide/ifmslide.sty:  \def\titlefont{\LARGE\color{title}\bfseries}
paper/paper.cls:\def\titlefont#1{\def\t@font{#1}}            \def\t@font{}
pdfslide/pdfslide.cfg:  \def\titlefont{\@setfontsize\titlefont{24}{26}\color{dm}\rmfamily\bfseries}
pdfslide/pdfslide.sty:  \def\titlefont{\@setfontsize\titlefont{24}{26}\color{dm}\rmfamily\bfseries}

$ popd

With line numbers (now that I read OP...)

$ grep -r -n '\\newcommand\*\\titlefont'
achemso/achemso.cls:582:\newcommand*\titlefont{\bfseries\sffamily}
koma-script/scrartcl.cls:2725:\newcommand*\titlefont{\sectfont}%
koma-script/scrbook.cls:2943:\newcommand*\titlefont{\sectfont}%
koma-script/scrextend.sty:1305:\newcommand*\titlefont{\sectfont}%
koma-script/scrreprt.cls:2940:\newcommand*\titlefont{\sectfont}%

The line 1225 refers to some other \newcommand*\titlefont.

5

If you started with one of those lousy templates, loading packages in dozens, you are in trouble.

As far as I can tell, there are only three ways to find out, which package defines a certain command.

Of course, you always search the source code of all used packages. OK, may take a long time.

Other option: list all packages you load here in your question, maybe somebody knows which package defines (in your case) \titlefont.

I suggest to make a new *.tex file of your long work and give a different name to this file. Keep the preamble. But delete (in the copy, not in your valuable original file!) everything except your text around line 1225.

If you are lucky, you can compile and get the same error. Then you can start to comment out packages until the error disappears. Take care, the error might disappear, because you get another error beforehand.

If you don't get along, take that copied file as a basis for an MWE.

We recently had a similiar question: How to find the packages causing an apparent incompatibility problem? . In the end, the guy who asked found the solution while building the MWE, but it really was a mean trap: a glossaries package loaded amsmath. The unicode-math package throws an error, if loaded before amsmath. Without MWE he'd never found out.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .