0

Below is my code

\documentclass{article}

\def\a{\alpha}
\def\b{\beta}
\def\a{\theta}

\newcommand\s{\alpha}
\newcommand\f{\beta}
\newcommand\s{\theta}

\begin{document}

Sample Text $\a$

\end{document}

My problem is I want to show error while compiling the document if I have multiple \def in same name, for example \def\a repeated twice, for \newcommand it shows error if mentioned twice, likewise I need for \def too, please guide,

  • 3
    \def is a TeX primitive and very deliberately doesn't do any checks: why can you not stick to \newcommand? – Joseph Wright Sep 29 '15 at 12:05
  • @JosephWright problem is we don't code the Latex files, it is being coded somewhere, where we can't give instructions to them to use a specific commands, Is it possible to make it check?? – user52124 Sep 29 '15 at 12:06
  • @user52124: Do you want to have something like \ifdef from etoolbox? – user31729 Sep 29 '15 at 12:12
  • @ChristianHupfer just need a Error message when i compile the Tex using PDFLATEX – user52124 Sep 29 '15 at 12:15
  • @user52124: I've posted an example. – user31729 Sep 29 '15 at 12:15
4

You can not do this. If you redefine \def not to be the tex primitive, then you will break almost every latex command.

As an aside, note \a is already defined in latex so if it did check you would get an error form the first shown \def not the second. Similarly \b is already defined.

You mentioned that the latex is being coded by someone else, you should report it as an error in that coding. \def is not a latex command and should not be used in latex documents (despite its widespread use in latex package files)

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.