I'm creating the XML from the TOC files, in this process I'm finding issue. on looking into the files there are many commands are getting expanded while writing. for example \hat has wrote in \mathaccentV {tilde}251{A}. when i have used \protect before the \hat its writing \hat in the toc. is there any method to produce the same content in the TOC without expansion

\chapter{This is a sample chapter $\hat{z}acffr$} 
\section{This is a sample section $\tilde{d}$} 

Aux file content:

\@writefile{toc}{\contentsline {chapter}{\numberline {1}This is a sample chapter $\mathaccent "705E\relax {z}acffr$}{1}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}
\@writefile{toc}{\contentsline {section}{\numberline {1.1}This is a sample section $\mathaccent "707E\relax {d}$}{1}}
  • Hi Steven, Thanks for your response. if possible can you code same example here. Apr 23, 2019 at 9:54
  • Is there any way to control this through macros as a global not in the case by case occurrences. Apr 23, 2019 at 9:58
  • You are supposed to provide the example that you are having difficulty with and then we try to adjust it to work. Please provide a short (but complete) non-working example. Apr 23, 2019 at 9:59
  • Does this question help? tex.stackexchange.com/questions/110883/writing-to-a-file Apr 23, 2019 at 10:02
  • 1
    \MakeRobust{\tilde} in the preamble.
    – egreg
    Apr 23, 2019 at 13:04

1 Answer 1


Rather than try to change the actual aux and toc files, I just write an additional file, fauxtoc.toc, that mimics the toc file, but is unexpanded.

This version is implemented for \chapter and \section, since that was what was mentioned by OP. Additional sectioning can be added.

The method draws on egreg's answer to this question: Writing \\ to a File

\chapter{Sample chapter $\hat{z}acffr$} 
\section{This is a sample section $\tilde{d}$} 

This produces a file fauxtoc.toc, which matches the proper toc file, except that the sectioning names are unexpanded


\contentsline {chapter}{\numberline {1}Sample chapter $\mathaccent "705E\relax {z}acffr$}{3}
\contentsline {chapter}{\numberline {2}$\mathaccent "705E\relax {z}acffr$}{5}
\contentsline {section}{\numberline {2.1}This is a sample section $\mathaccent "707E\relax {d}$}{5}


\contentsline {chapter}{\numberline {1}Sample chapter $\hat {z}acffr$}{3}
\contentsline {chapter}{\numberline {2}$\hat {z}acffr$}{5}
\contentsline {section}{\numberline {2.1}This is a sample section $\tilde {d}$}{5}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.