1

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?

8
  • 2
    Welcome! I guess this is more about the text editor rather than LaTeX itself.
    – egreg
    Mar 3, 2021 at 14:25
  • Why don't you use \lbrace and \rbrace?
    – SebGlav
    Mar 3, 2021 at 14:28
  • @egreg I'm sorry, I don't really know the difference! It's Overleaf in this case.
    – Bcpicao
    Mar 3, 2021 at 14:45
  • 1
    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.
    – daleif
    Mar 3, 2021 at 16:18
  • 1
    The interface in Overleaf is a bit borked. Using \newcommand{\abs}[1]{\left|#1\right|} just prompts \abs during autocomplete. However, using \newcommand\abs[1]{\left|#1\right|} prompts \abs[]{} during autocomplete. The former use of \newcommand is even suggested in the autocomplete, but only the latter suggests an improved autocomplete option. Of course, since there's no optional argument, it should just suggest \abs{}. This seems like something that is better to report to Overleaf directly as it's an issue with the online editor, or finding someone here that provides support.
    – Werner
    Mar 3, 2021 at 16:18

2 Answers 2

1

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.

enter image description here

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

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!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.