AnswerBun.com

Redefining Commands: Safety and Best Practices

TeX - LaTeX Asked on August 13, 2020

There’s plenty of questions on this site about redefining specific commands, but I couldn’t find a more general, comprehensive question about the safety and best practices of redefining commands in LaTeX.

Answers to specific parts of this question are welcome, but most likely have already been formulated on this site somewhere; links to those would also be welcome, of course.

Specific recommendations for further reading (chapters in books, specific content on other websites, etc.) are also welcome.


  1. Redefining a Command: what are the implications for packages I’m loading that use said command, for lower-level places that use said command (e.g. the documentclass, or for higher-level places (mostly meaning just calls to commands from packages which directly or indirectly depended upon the old command), and how do they depend on:

    1. where the original command is defined?

      • defined in a package I’m loading, in the documentclass I’m using, in the TeX engine I’m using, my own preamble, etc.
    2. where the redefined command is defined?

      • before or after begin{document}?
      • before or after usepackage{ <package that depends on the old command> }?
      • in a small space in the document enclosed with bgroup and egroup that does / doesn’t make use of some / any functionality of the affected package(s).
    3. how the original command is defined?

      • newcommand, def, edef, protecteddef, NewDocumentCommand, DeclareExpandableDocumentCommand, DeclareRobustCommand, etc.
      • content of the original command (i.e. e.g. in the original newcommand{cmd}{ <old content> })
    4. how the redefined command is defined?

      • renewcommand, patchcmd, xpatchcmd, RenewDocumentCommand, RenewExpandableDocumentCommand, renewrobustcmd, etc.
      • content of the redefined command (i.e. e.g. renewcommand{cmd}{ <new content> })
    5. whether the old command is renamed with e.g. letoldcmd=cmd

      • how it is renamed?
    6. how the old command was being made use of?

  2. Redefining a TeX Primitive (e.g. neq or par)…

    1. Is it always a no-go, or does it depend on the specific primitive or "type" thereof?
    2. Same questions as above

What led me to ask this question, which has popped into my head plenty of times before, was my intention to redefine the TeX primitive d, whose original definition is (TeXbook p. 356):

defd#1{oalign{#1crcrhidewidth.hidewidth}}

I wanted to redefine it into an all-purpose derivative operator, that e.g. becomes frac{mathop{}!mathrm{d}f}{mathop{}!mathrm{d}x} when given two arguments, mathop{}!mathrm{d} when given one, uses partial when starred, higher derivatives if given an optional argument, etc. How to achieve this particular behavior is, of course, not this question.


Related resources

Add your own answers!

Related Questions

Bra-ket notation typefaces

1  Asked on May 13, 2021 by eigenaus

     

move legend in tikzpicture

1  Asked on May 13, 2021

     

Removing right margin in Verse environment

1  Asked on May 13, 2021 by raphael-soares

   

What are refhg, refmark, refhgb?

0  Asked on May 13, 2021 by dfrankow

 

Typesetting Preparsed Verbatim Text/Code

1  Asked on May 12, 2021 by kelly-smith

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP