如何在数学中换行

发布于 2024-08-10 09:25:29 字数 597 浏览 3 评论 0原文

我想表达以下句子(source_location也是斜体,它没有正确呈现):

每个条目都有一个元组列表:< 源位置读/写行程计数器发生死亡(在稍后)>

我目前的解决方法是:

$ \left\langle
\textit{source\_location}, \textit{R/W}, \textit{trip\_counter},
\textit{occurrence}, \textit{killed} \text{(explained in the later)}
\right\rangle $

我使用 2 列纸张。这< ..>太长了,但没有换行,因为它是数学题。在这种情况下如何自动(或手动)换行?看来 \left\langle\right\rangle 应该在一个数学中。所以,很难闯入多项数学。

$<$$>$ 是一个替代方案,但我不喜欢它。

I'd like to express the following sentence (source_location is also italic, it's not correctly rendered):

Each entry has a list of tuple: < source_location, R/W, trip_counter, occurrence, killed (explained in the later) >

My current workaround for this is:

$ \left\langle
\textit{source\_location}, \textit{R/W}, \textit{trip\_counter},
\textit{occurrence}, \textit{killed} \text{(explained in the later)}
\right\rangle $

I'm using 2-column paper. This < .. > is too long, but no line break because it is a math. How do I automatically (or manually) put line break in such case? It seems that \left\langle and \right\rangle should be in a single math. So, hard to break into multiple maths.

$<$ and $>$ would be an alternative, but I don't like it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

油饼 2024-08-17 09:25:29

默认情况下,LaTeX 确实允许内联数学突破行,但有许多限制。具体来说,在您的情况下,使用 \left...\right 将所有内容放入不可破坏的数学组中,因此第一步是将它们替换为普通的 \langle.. .\rangle\bigl\langle...\bigr\rangle

然而,这仍然不足以允许换行;通常仍然只允许在关系或运算符之后使用,而不是像逗号这样的标点符号。 (我认为这就是正在发生的事情;我还没有停下来查找这一点。)因此,您希望通过在每个逗号后写入 \linebreak[1] 来指示允许的换行符可能发生的位置。

根据您执行此操作的频率,最好编写一个命令将您的“元组”包装成一个不错的命令。为了在源代码中编写此内容:

$ \mytuple{ source\_location, R/W, trip\_counter, occurrence,
    killed\upshape (explained in the later) } $

这里是 \mytuple 的定义,它考虑了上述所有内容:

\makeatletter
\newcommand\mytuple[1]{%
  \@tempcnta=0
  \bigl\langle
  \@for\@ii:=#1\do{%
    \@insertbreakingcomma
    \textit{\@ii}
  }%
  \bigr\rangle
}
\def\@insertbreakingcomma{%
  \ifnum \@tempcnta = 0 \else\,,\ \linebreak[1] \fi
  \advance\@tempcnta\@ne
}
\makeatother

LaTeX does allow inline maths to break over lines by default, but there are a number of restrictions. Specifically, in your case, using \left...\right puts everything inside a non-breakable math group, so the first step is to replace them with either just plain \langle...\rangle or perhaps \bigl\langle...\bigr\rangle.

However, this still isn't enough to permit linebreaking; usually that's still only allowed after relations or operators, not punctuation such as the comma. (I think this is what's going on anyway; I haven't stopped to look this up.) So you want indicate where allowable line breaks may occur by writing \linebreak[1] after each comma.

Depending how often you have to do this, it may be preferable to write a command to wrap your "tuples" into a nice command. In order to write this in your source:

$ \mytuple{ source\_location, R/W, trip\_counter, occurrence,
    killed\upshape (explained in the later) } $

here's a definition of \mytuple that takes all of the above into account:

\makeatletter
\newcommand\mytuple[1]{%
  \@tempcnta=0
  \bigl\langle
  \@for\@ii:=#1\do{%
    \@insertbreakingcomma
    \textit{\@ii}
  }%
  \bigr\rangle
}
\def\@insertbreakingcomma{%
  \ifnum \@tempcnta = 0 \else\,,\ \linebreak[1] \fi
  \advance\@tempcnta\@ne
}
\makeatother
烟织青萝梦 2024-08-17 09:25:29

为什么不定义一个新命令:

\newcommand{\tuple}[5]{$\langle$\textit{#1}, \textit{#2}, \textit{#3}, \textit{#4},
   \textit{#5} (explained in the latter)$\rangle$}

然后使用 \tuple{sourcelocation}{R/W}{tripcounter}{occurrence}{killed}

Why not define a new command:

\newcommand{\tuple}[5]{$\langle$\textit{#1}, \textit{#2}, \textit{#3}, \textit{#4},
   \textit{#5} (explained in the latter)$\rangle$}

Then use \tuple{sourcelocation}{R/W}{tripcounter}{occurrence}{killed}

丘比特射中我 2024-08-17 09:25:29

似乎有一个软件包可以解决这个问题,名为breqn 。您可以尝试一下并告诉我们(我没有使用过)。

There seems to be a package that addresses that problem, called breqn. You can try this and let us know (I haven't used that).

亢潮 2024-08-17 09:25:29

我会使用 AMSmath 的align*环境。此外,您可以只添加“\”来换行吗?也应该在数学环境中工作。或者,您可以分离方程。

I'd use the align* environment from AMSmath. Furthermore you could just add "\" to break the lines? Should work in math environments, too. Alternatively you could separate the equations.

尾戒 2024-08-17 09:25:29

在数学表达式中任何需要换行的地方(甚至在两个括号之间)都可以使用 \linebreak。这将强制断线。

Use \linebreak inside the math expression wherever you want a new line even between 2 brackets. This will enforce the line to be broken.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文