Text FormattingDefining a command for a fraction

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
artemff
Posts: 113
Joined: Sat Oct 17, 2009 11:15 pm

Defining a command for a fraction

Post by artemff »

Code: Select all

\newcommand{\inv}[1]{\frac{1}{#1}}

Recommended reading 2024:

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

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

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Defining a command for a fraction

Post by frabjous »

It does work. I just tried compiling the following:

Code: Select all

\documentclass{article}
\newcommand{\inv}[1]{\frac{1}{#1}}
\begin{document}
$\inv{5}$
\end{document}
It worked as expected.

You might improve it as follows... and then you can use it either in or outside of math mode:

Code: Select all

\documentclass{article}
\newcommand{\inv}[1]{\ensuremath{\frac{1}{#1}}}
\begin{document}
\inv{5}
\end{document}
If it's not working for you, post a minimal example that shows the problem.
artemff
Posts: 113
Joined: Sat Oct 17, 2009 11:15 pm

Re: Why this command don't work?

Post by artemff »

>>frabjous
Thanks, now all work... Other problem generates error...
Post Reply