Skip to Content
🎉 TexSlide is released. Read more →
DocumentationDefine Macros

In the global preamble, you can define custom macro commands for use by all LaTeX content in the current document. TexSlide supports two macro definition methods: \newcommand or \def。

newcommand Method

\newcommand is a high-level command definition tool provided by the LaTeX kernel. It checks whether a command already exists, preventing accidental overwriting of existing commands.

Syntax Format

\newcommand{\<commandname>}[<numargs>][<default>]{<definition>}
  • \<commandname>:The name of the command to define, must begin with a backslash \, for example, \mycommand.
  • [<numargs>]:Optional parameter specifying the number of arguments (0-9). Omit if the command takes no arguments.
  • [<default>]:Optional parameter defining a default value for the first argument. Requires at least one argument.
  • {<definition>}:The concrete definition of the command. Use #1, #2, ..., #9 to reference the arguments.

Video Demonstration

def Method

\def is a TeX primitive command. It is powerful but does not check for existing commands, overwriting them directly. It can define complex macros that \newcommand cannot handle.

Syntax Format

\def\<commandname><parameter>{<definition>}
  • \<commandname>:The name of the command to define.
  • <parameter>:Defines how arguments are recognized, obtained through macro pattern matching.
  • {<definition>}:The concrete definition of the command. Use #1, #2, ... to reference the arguments.

Video Demonstration

Use \def with extreme care, as it performs no safety checks and will silently overwrite any existing command. Prefer \newcommand for all simple, standard parameter command definitions.

Last updated on