143 days ago · Tech · hide · Fediverse post

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…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town