If you’re using LaTeX to write a document (article, thesis, grocery list, etc.), you can define your own custom commands to save you time and make your code look cleaner. At the beginning of your document include the line

\newcommand{\newtag}{whatever_you_want}

Now, if you type “\newtag” in your LaTeX code, it will be automatically substituted with “whatever_you_want” when the LaTeX is compiled! This is great, but you can do even more. Changing the syntax slightly, you can pass arguments to these macros so that they become little functions. For instance if you want a quicker way to make things bold, include

\newcommand{\bt}[1]{\textbf{#1}}

Now, if you type “\bt{x}”, you’ll get “\textbf{x}” which will be interpreted as x. In this syntax, the number in []’s is the number of arguments the macro should expect, and it is referenced as #1. You can also do this with multiple arguments like this

\newcommand{\vfrac}[2]{\ensuremath{\frac{#1}{#2}}}

When you call this you’d type \vfrac{a}{b} to make a fraction a/b. There will be a set of {} for each argument. In this command I also used the \ensuremath{} command. This command allows you to put ‘math’ commands into regular text or in equations, and is a big help when writing papers!

I hope this information helps you. Thanks to these guys for posting the info I finally found when I needed to find out.

2 thoughts on “\newcommand with arguments in LaTeX

  1. The retail Sun Labs spray tan gives beautiful golden or bronzed appearance
    and last for a few days in the least. If you’ve just had a bath or shower and use an alkaline soap, wait about 30 minutes so that your skin can return to
    its normal p – H value prior to application. When it comes to getting the perfect (and safe)
    tan in a flash we run to our bronzing savor, Jimmy Coco.

    Water accelerates the fading process, so the
    less you are in contact with water the slower it will
    fade. When using self-tanner on your face wait at least 45 minutes before applying any
    moisturizers or make-up. Apply this on your underarms and leave this on for 15
    minutes before washing them off thoroughly. Although the
    desire to look good is still there but the scenario has changed a lot.
    There is nothing wrong in it as far as it gives them a
    healthy glow. People enjoy watching others’ pains and problems
    from the comfort of their own living rooms. You can rely completely on their products because they
    are made up of natural ingredients and do not have any side-effects.

Leave a Reply

Your email address will not be published.