Math & ScienceNumber for in-line Equations

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Willie
Posts: 42
Joined: Sat Aug 27, 2011 3:43 am

Number for in-line Equations

Post by Willie »

Hello. I would like to insert equations in regular text (so that it doesn't span separate lines) and continue the numbering scheme from 'equation' environments. Is it possible? I tried
$x^2=3 \tag$ which doesn't work.

By the way, is this the preferred way to do this? I also tried to just use 'equation' environment and insert text with \text{} but the problem is that the text is justified to the middle of the line, unlike other regular text in the document.

thanks

Recommended reading 2024:

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

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

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

Number for in-line Equations

Post by localghost »

Willie wrote:[…] By the way, is this the preferred way to do this? […]
No.
Willie wrote:[…] I also tried to just use 'equation' environment and insert text with \text{} but the problem is that the text is justified to the middle of the line, unlike other regular text in the document. […]
Please clarify with a proper minimal example what you are after.


Thorsten
Willie
Posts: 42
Joined: Sat Aug 27, 2011 3:43 am

Number for in-line Equations

Post by Willie »

example:

Code: Select all

\documentclass[a4paper,10pt,english]{article}
\begin{document}
	This is my first numbered equation:
	\begin{equation}
		x^2=9
	\end{equation}
	Now I want the following equation: $x=5$ and also the following: $y=8$ to be numbered.
\end{document}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Number for in-line Equations

Post by localghost »

I was sure that this has been discussed here already. After a forum search I found something that might be useful [1]. Unfortunately the OP didn't respond in that topic. So it's not sure if the provided solution works as expected.

[1] View topic: Numbering in-line Equations
Willie
Posts: 42
Joined: Sat Aug 27, 2011 3:43 am

Number for in-line Equations

Post by Willie »

localghost wrote:I was sure that this has been discussed here already. After a forum search I found something that might be useful [1]. Unfortunately the OP didn't respond in that topic. So it's not sure if the provided solution works as expected.

[1] View topic: Numbering in-line Equations
Thanks for your reply. In the referred forum post the author assigns a new counter for the inline-text equations. However, I am looking to use the same number scheme in my text-inline equations (math enviroment) as in the equation enviroment.
i.e. in my example, if
\begin{equation}
x^2=9
\end{equation}
assigned the number (1), I want the $x=5$ to be number (2) and $y=8$ to be number (3).
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Number for in-line Equations

Post by localghost »

Then you have to use the given equation counter in the new command.

Code: Select all

\documentclass[11pt]{article}
\usepackage{amsmath}

\newcommand{\ilmath}[1]{%
  \refstepcounter{equation}%
  \(#1\)\enspace(\theequation)%
  \ignorespacesafterend
}

\begin{document}
  This is my first numbered equation:
  \begin{equation}
    x^2=9
  \end{equation}
  Now I want the following equation: \ilmath{x=5} and also the following: \ilmath{y=8} to be numbered.
\end{document}
Willie
Posts: 42
Joined: Sat Aug 27, 2011 3:43 am

Number for in-line Equations

Post by Willie »

localghost wrote:Then you have to use the given equation counter in the new command.

Code: Select all

\documentclass[11pt]{article}
\usepackage{amsmath}

\newcommand{\ilmath}[1]{%
  \refstepcounter{equation}%
  \(#1\)\enspace(\theequation)%
  \ignorespacesafterend
}

\begin{document}
  This is my first numbered equation:
  \begin{equation}
    x^2=9
  \end{equation}
  Now I want the following equation: \ilmath{x=5} and also the following: \ilmath{y=8} to be numbered.
\end{document}
Thanks, it does work in that example. However, when I try it in my big document it produces errors. I would post a picture but I don't see an option here.

Also, is it possible to use \equation enviroment but have it aligned to the left, and not center-adjusted?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Number for in-line Equations

Post by localghost »

Willie wrote:[…] However, when I try it in my big document it produces errors. […]
Then you have to reduce your document to a minimal example that still reproduces the error(s) and present it here.
Willie wrote:[…] I would post a picture but I don't see an option here. […]
Pictures can simply be attached by upload to the forum server while composing a message. But a picture is not as informative as code which can be tested (see above).
Willie wrote:[…] Also, is it possible to use \equation environment but have it aligned to the left, and not center-adjusted?
Set the »fleqn« option for the document class and modify the length \mathindent accordingly.
Willie
Posts: 42
Joined: Sat Aug 27, 2011 3:43 am

Re: Number for in-line Equations

Post by Willie »

About the code - I may look for producing a shorter version later, but it's long, and it will take time. anyway I think the error message will help, but I can't find how to attach a picture fle. I see only [img]tag which is for URL.

I know about the option of fleqn, but I want to do this only for one equation, not for all of them.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Number for in-line Equations

Post by localghost »

Willie wrote:About the code - I may look for producing a shorter version later, but it's long, and it will take time. […]
You've got all the time in the world.
Willie wrote:[…] anyway I think the error message will help, but I can't find how to attach a picture fle. I see only [img]tag which is for URL. […]
Right beneath the input window while composing a message you will find a tab "Upload attachment". The rest should be self-explanatory. But I think that regarding error messages attaching the corresponding log file is much better. Nevertheless it's best to have a minimal example.
Willie wrote:[…] I know about the option of fleqn, but I want to do this only for one equation, not for all of them.
Search the amsmath manual for the flalign environment. Useful information can also be found in the »Math mode« document.
Post Reply