logo

Creating a New Command in LaTeX That Acts Like a Function Using the begin...end Structure 📂Writing

Creating a New Command in LaTeX That Acts Like a Function Using the begin...end Structure

Code

Writing TeX code with \begin{}...\end{} statements can be quite bothersome.

\documentclass{article}

\usepackage{amsthm}

\newtheorem*{theorem*}{Theorem}

\begin{document}

\begin{theorem*}
    Let $f$ and $g$ be continuous functions on a metric space $X$. Then $f + g$, $fg$, and $f/g$ are continuous on $X$. 
\end{theorem*}

\end{document}

By adding a new command like \newcommand{\thm}[1]{\begin{theorem*}#1\end{theorem*}}, it can be conveniently used.

\documentclass{article}

\usepackage{amsthm}

\newtheorem*{theorem*}{Theorem}
\newcommand{\thm}[1]{\begin{theorem*}#1\end{theorem*}}

\begin{document}

\thm{
    Let $f$ and $g$ be continuous functions on a metric space $X$. Then $f + g$, $fg$, and $f/g$ are continuous on $X$. 
}

\end{document}