Math & ScienceInserting parenthesis in new math command

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
c1b3rz
Posts: 6
Joined: Fri Sep 28, 2012 8:01 pm

Inserting parenthesis in new math command

Post by c1b3rz »

Say I want to create a new math command

Code: Select all

\newcommand{\mycmd}{\operatorname{mycmd}}
And I want the argument of it to be automatically put inside parenthesis, say:

Code: Select all

\mycmd{argument}
and I wish the output to be

Code: Select all

\mycmd{\left( argument \right)}
How should it be done?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Inserting parenthesis in new math command

Post by localghost »

Perhaps something like this.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}    % loads »amsmath«

\DeclareMathOperator*{\mycmd}{mycmd}
\DeclarePairedDelimiter{\parens}{(}{)}

\begin{document}
  \[
    \mycmd\parens*{\frac{a}{a}}
  \]
\end{document}
For more details refer to the mathtools manual.


Thorsten
Post Reply