0

I have the code in which an equation environment is in \hbox:

\documentclass{article}

\begin{document}

\hbox{ \begin{equation} F=ma \end{equation} }

\end{document}

But it throws multiple errors. What should I correct?

Edit: \hbox is used in the code in NewEnviron. When I try to insert an equation environment in \item, the same errors occur.

Hermis14
  • 423
  • 2
    Why not just remove the \hbox? What is it you want to achieve? – Werner Oct 15 '21 at 03:11
  • @Werner I use \hbox in the code: \setbox0=\hbox{...}. – Hermis14 Oct 15 '21 at 03:23
  • 2
    Have you tried replacing \setbox0=\hbox{...} with \setbox0=\vbox{...}? (I will also confess to having no idea what it is that you want to achieve.) – Mico Oct 15 '21 at 03:54
  • 1
    Please show us a short example of complete document, where you use your hbox. Without seeing context of it use we can only (unsuccessful) guess how to help you. – Zarko Oct 15 '21 at 04:54
  • @Zarko I added the link to the entire code. – Hermis14 Oct 15 '21 at 04:58
  • 1
    As I see now, your question is duplicate to the question in the link. BTW, There is not complete (compilable) document but only fragment with definition. – Zarko Oct 15 '21 at 05:01
  • In the context of the linked question, it makes no sense to use an equation environment, which by the way occupies the whole text width (besides being illegal in \hbox). – egreg Oct 15 '21 at 07:22

1 Answers1

3

You can not have a vertical construct like an equation in an hbox you could use a vertical box (\vbox or better a latex construct using \vbox such as \parbox or minipage).

Alternatively use inline math \(...\) not a display construct.

David Carlisle
  • 757,742
  • I decided to use \vbox. Thank you. – Hermis14 Oct 15 '21 at 16:48
  • @Hermis14 but it's hard to see what \vbox will do there that is useful, what is the use case? – David Carlisle Oct 15 '21 at 17:04
  • The code provided in [https://tex.stackexchange.com/a/130099/142888] uses \hbox in \setbox0=\hbox{\BODY}. But I don't know why he used it though he explained the reason. After I replace \hbox with \vbox, it works as I want. – Hermis14 Oct 15 '21 at 17:52
  • @Hermis14 oh I guess so, it's just setting it and throwing it away so vbox is safer than hbox certainly – David Carlisle Oct 15 '21 at 18:05