Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I searched the internet but I cant find a solution for my problem. I want a numbered and labelled equation inside the text.Something like:

The equation a+1=b (2.1) does ...

The equation a+1=b shouldn't be in a new line like usual

The equation
a+1=b (2.2)
does...
share|improve this question
1  
Hi Paul, Welcome to TeX.SE! I edited the title of your question- hope it's ok :) If not, please feel free to role it back. Welcome to the group! –  cmhughes Oct 21 '12 at 20:19
add comment

2 Answers

up vote 10 down vote accepted

The following defines \inlineequation:

\inlineequation[<label name>]{<equation>}
  • Optionally <label name> can be given for referencing the equation.
  • \label afterwards keeps the previous referencing behavior like an environment equation would have done.
  • \refstepcounter is called at the beginning of the inline equation, because package hyperref sets the anchor here.
  • A numbered equation should probably not be broken across lines. This is prevented by the penalty settings at the beginning without loosing stretchability of glues. With \hbox or \mbox the strechability would be lost.
  • The equation number is set by \@eqnnum that takes care of the formatting of the equation number as in environment equation. It is responsible for adding parentheses and font settings.

The example file:

\documentclass{article}

\makeatletter
\newcommand*{\inlineequation}[2][]{%
  \begingroup
    % Put \refstepcounter at the beginning, because
    % package `hyperref' sets the anchor here.
    \refstepcounter{equation}%
    \ifx\\#1\\%
    \else
      \label{#1}%
    \fi
    % prevent line breaks inside equation
    \relpenalty=10000 %
    \binoppenalty=10000 %
    \ensuremath{%
      % \displaystyle % larger fractions, ...
      #2%
    }%
    ~\@eqnnum
  \endgroup
}
\makeatother

\usepackage{hyperref}

\begin{document}
The equation        
\inlineequation[eq:inline]{a+1=b}
does \dots
\end{document}

Result

share|improve this answer
add comment

I'm not sure if this is a good idea or not (imagine a new reader searching for equation 2.1, for example), but the following seems to do what you want; note that I've used refstepcounter to increment the equation counter.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
The equation $a+1=b~\refstepcounter{equation}(\theequation)\label{myeq}$

Here is a reference: \eqref{myeq}

\end{document}
share|improve this answer
3  
Not a good idea, also in my opinion, for the same reason you mention. –  egreg Oct 21 '12 at 20:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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