# How to define a command to include brackets?

This is a lazy question but I want to define a command like so

\newcommand{\abs}[1]{\ensuremath{\left|{#1}\right|}}

But this doesn't automatically present the { } so I can include the argument the same way a \mathbb{} does. Any idea how I can include those in the definition? Can't seem to figure that out.

EDIT: I don't think I quite got my point across, so let me reiterate: When I type "\mat" into Overleaf, it immediately suggests "\matbb{}" and auto-completes with the curly brackets, whereas, when I type "\a" it auto-completes to "\abs" without the brackets. So I then have to type the brackets each time to insert the argument. Is there a way to define my command so that it does paste with the brackets?

• Welcome! I guess this is more about the text editor rather than LaTeX itself. Mar 3, 2021 at 14:25
• Why don't you use \lbrace and \rbrace? Mar 3, 2021 at 14:28
• @egreg I'm sorry, I don't really know the difference! It's Overleaf in this case. Mar 3, 2021 at 14:45
• That is not really a LaTeX issue but rather an issue with the overleaf interace. You should tag the question with overleaf as well. BTW: I'd use mathtools to define \abs as the construction cited is wrong in may ways. Mar 3, 2021 at 16:18
– Werner
Mar 3, 2021 at 16:18

This is not a Tex/LaTeX problem but rather the autocompletion of your Tex editor (Overleaf in that case). For instance, if you used an editor such as TexStudio, it will complete with the brackets (see picture).

Going through the documentation of Overleaf about specifying your own commands, I haven't seen anything to trigger something for that. Maybe you can write to them and ask for this feature.

• Thanks! I am gonna try to contact them then! Mar 3, 2021 at 19:56

I talked to Overleaf support and they answered me with this:

For user-provided commands, the autocomplete looks at the usage in the document, and it can pick up the definition of the new command as a "first usage" and not recognize the need for parameters.

So, one approach is to move your definition into a separate file that you input directly - the first usage should be one with parameters.

In this example project, I've defined two commands, one in the main.tex file and one in a separate commands.tex file: https://www.overleaf.com/read/dnqcccxkjyjz. The command defined in the main project will appear in autocomplete with no brackets, but the second command will only show up as how I've used it in the main.tex.

Although I believe there is no need for that since after the first use with brackets, it automatically autocompletes with brackets again (actually, it proposes both autocompletes). Mystery solved!

• Also, can someone tell me how to blockquote several paragraphs without them breaking apart like so? Mar 16, 2021 at 11:57