[Tex/LaTex] Command already defined, but where

errorsincompatibility

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.

Best Answer

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.