# Error: Missing \endcsname inserted.<to be read again> \tex_let:D \begin{}

I'm using texmaker 4.5. I'm trying to compile the following text on Windows 10:

\documentclass[english]{MastersDoctoralThesis}
\begin{document}
\frontmatter
\begin{titlepage}

The Title.

\end{titlepage}
\begin{declaration}

The Declaration.

\end{declaration}
\end{document}


But when I compile it, the following error appears:

''! Missing \endcsname inserted.
\tex_let:D
\begin{document}''


How can I solve it?

The template can be found at: http://www.latextemplates.com/template/masters-doctoral-thesis

• Welcome to TeX.SX! Please make your example minimal (not using any special class and too much unnecessary informationg). It shall be compilable. Mar 4, 2017 at 10:34
• The problem is related to the latest update to xparse which is used inside, but the main cause is the wrong usage of \NewDocumentCommand etc. by the author of the MDT class.
– user31729
Mar 4, 2017 at 10:51
• Try \makeatletter \AtBeginDocument{ \renewcommand{\blank@p@gestyle}{empty} } \makeatother
– user31729
Mar 4, 2017 at 10:53
• If the OP would have left the comment header, nobody here would have had any need to use google. Mar 4, 2017 at 10:57

Update: 2017/03/09 With the new update of xparse and expl3 packages from 2017/03/07 it is possible to use commands defined with \DeclareDocumentCommand in \csname ...\endcsname constructs ago, which is the case in the background code of \pagestyle, for example.

The \blank@p@gestyle macro is defined in MDT with \DeclareDocumentCommand which isn't expandable, but \pagestyle needs an expandable name, so this fails.

With this bypassing code

\makeatletter
\AtBeginDocument{
\renewcommand{\blank@p@gestyle}{empty}
}
\makeatother


the macro is exandable again.

A future release of xparse will remove the necessity of this bypass.

This tiny document shows the same error (and is the short version of what happens)

\documentclass{article}

\usepackage{xparse}

\DeclareDocumentCommand{\foo}{}{empty}

\begin{document}
\pagestyle{\foo}

\end{document}

• Do you mean it will remove the need for the bypass? What you say right now means it will break when it is updated ....
– cfr
Mar 4, 2017 at 22:28
• @cfr Means L3 team decided to go a step backward not to break peoples code, on the other hand, i guess the template will be updated to not need that bypass. Mar 5, 2017 at 6:42
• @Johannes_B Yes, but that's not what the answer says.
– cfr
Mar 5, 2017 at 17:07
• @cfr Not what it says, but what it was meant to say. Maybe Christian needs to reword stuff. Mar 5, 2017 at 18:17
• @Johannes_B: Reworded
– user31729
Mar 5, 2017 at 18:53

The template shows a few wrong usages of \NewDocumentCommand and \DeclareDocumentCommand.

For instance,

\NewDocumentCommand{\supervisor}{m}{%
\DeclareDocumentCommand{\supname}{}{#1}%
}


(code reformatted for readability) should be

\newcommand\supname{}
\NewDocumentCommand{\supervisor}{m}{%
\renewcommand\supname{#1}%
}


because \supname is just a variable, not a document command. Better, using expl3 programming, assuming \ExplSyntaxOn is in force,

\NewDocumentCommand{\supervisor}{m}
{
\tl_set:Nn \supname { #1 }
}


Better yet,

\tl_new:Nn \g_mdt_supname_tl

\NewDocumentCommand{\supervisor}{m}
{
\tl_gset:Nn \g_mdt_supname_tl { #1 }
}


and, if \supname is allowed to be used in the document,

\cs_new:Npn \supname { \tl_use:N \g_mdt_supname_tl }


The particular problem stems from

\NewDocumentCommand{\blank@p@gestyle}{}{empty}


which should be

\tl_set:Nn \blank@p@gestyle { empty }


\newcommand\blank@p@gestyle{empty}


because the argument to \pagestyle should be fully expandable, which something defined by \NewDocumentCommand isn't.

Similarly,

\NewDocumentCommand{\setblankpagestyle}{ m }{%
\DeclareDocumentCommand{\blank@p@gestyle}{}{#1}%
}


should be

\NewDocumentCommand{\setblankpagestyle}{ m }
{
\tl_set:Nn \blank@p@gestyle { #1 }
}


\NewDocumentCommand{\setblankpagestyle}{ m }{%
\renewcommand\blank@p@gestyle{#1}%
}
`