15 hours ago · Tech · hide · 0 comments

Throughout this series, we have used various commands and environments from multiple LaTeX packages. It's time to do a brief overview of various ways to create your own. Contents Built-in capabilities def let newcommand Starred commands newenvironment Xparse Built-in capabilities ↩ def ↩\def<\command><params>{<body>} This is the simplest way to define a command in LaTeX. \def\mydef{% This is expanded from \textbackslash mydef.% } Then, when invoked in the document as \mydef, it will expand to This is expanded from \mydef. The comment marks (%) are added to be sure that no extra new lines are added to the output. You can also specify the command arguments, from #1 to #9: \def\mydef#1#2{% Argument 1: #1;\\ Argument 2: #2.% } When called like \mydef{First argument}{Second argument}, this will output the following text: Argument 1: First argument; Argument 2: Second argument. Since \def won't check if the command is already defined, you might want to check for this manually: \ifx…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.