TransWikia.com

Is this possible for inline math line breaks: Have symbol duplicated on the next line?

TeX - LaTeX Asked on August 13, 2021

In certain typographical conventions, it is customary to duplicate symbols of binary mathematical operators when a line break occurs. For instance, if a + b = c is broken at +, the result would be a + on the first line, and + b = c on the second line. Duplication also occurs for logical connectives (Longrightarrow), and relation symbols which are binary (=), and several arrows (xrightarrow).

The exception to this would be the binary minus sign, . As example, a – b = c would become a + on the first line, and – b = c on the second line.

Question: Is there a way to do such breaking globally but for inline math only in an automatic way?

Here’s an MWE that might be tested to work properly should you choose to answer this question.

documentclass[12pt]{article}
usepackage[utf8]{inputenc}
usepackage[LGR,T1]{fontenc}
usepackage[english]{babel}
usepackage{amsmath}
usepackage{amssymb}
usepackage{amsthm}
usepackage{mathtools}
usepackage{titlesec}
usepackage[pdftex]{graphicx}
usepackage{parskip}
usepackage[a4paper]{geometry}

%Solution code might go here%

begin{document}

$a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a$

$b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b$

$c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c==c=c=c=c=c=c=c=c=c=c=c=c=c$

$dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow d$

$exrightarrow{ntoinfty} exrightarrow{ntoinfty} exrightarrow{ntoinfty} exrightarrow{ntoinfty} exrightarrow{ntoinfty} exrightarrow{ntoinfty} exrightarrow{ntoinfty} exrightarrow{ntoinfty} exrightarrow{ntoinfty} exrightarrow{ntoinfty} exrightarrow{ntoinfty} exrightarrow{ntoinfty} e$

end{document}

Note: $$-s are used on purpose. Also: I’m using pdfLaTeX if this is important. (The loaded packages are not really important, however do serve as some kind of a selection. If the proposed solution does not interfere with common packages, that would be ideal).


A previous question looked at doing this only for = and leq. Is there a more general way without having to specify each symbol separately?

This is also related but less so.

One Answer

As suggested by egreg, the package rmathbr is pertinent here. It provides options for most things asked in the OP. Please be sure to use the latest version of rmathbr (at time of writing, this is December 2020).

  • Various bugs were fixed, e.g. coloneqq now works.
  • I usually load it after most packages, except possibly bookmark, geometry and the similar.
  • See also: documentation. Known issues: with breqn package. With commath makes := asymmetric again even though loading commath makes it symmetric. But coloneqq is unaffected (works fine).

For many types of breaks, just loading the package is sufficient. The rest of the answer is dedicated to answering specific wishes in OP which need some additional code (parts 1, 2 and 3).


  1. New relations/operations that do not have variable arguments

To get a breakable n to infty arrow stuff, define goesto in the preamble like so:

newcommand{goesto}{xrightarrow{ntoinfty}}
SetBreakableRel{goesto}
  1. New relations/operations that DO contain variable arguments

To get a breakable a to b arrow stuff (with a and b variables), define goestoarg in the preamble like so:

DeclareRobustCommand{goestoarg}[2]{brokenrel{xrightarrow{#1to#2}}}

(Of course, you can generalise that syntax to suit your needs).

  1. Getting an asymmetrically breakable minus

To get a – b break up as a – and + b, add the following code in the preamble:

makeatletter
defminus@char{mathchar8704}
defplus@char{mathchar8235}
defrmathbr@selector#1{%
  defx@char{#1}%
  ifxx@charminus@chardefx@char{plus@char}fi%
  mathchoice
    {discretionary{}{hbox{$m@thdisplaystylex@char$}}{}}
    {discretionary{}{hbox{$m@thtextstylex@char$}}{}}
    {discretionary{}{hbox{$m@thscriptstylex@char$}}{}}
    {discretionary{}{hbox{$m@thscriptscriptstylex@char$}}{}}%
}
makeatother

Here is the output of an MWE (see after picture):

Output of MWE


MWE code:

documentclass[12pt]{article}
usepackage[utf8]{inputenc}
usepackage[LGR,T1]{fontenc}
usepackage[english]{babel}
usepackage{amsmath}
usepackage{amssymb}
usepackage{amsthm}
usepackage{mathtools}
usepackage{titlesec}
usepackage[pdftex]{graphicx}
usepackage{parskip}
usepackage{rmathbr} %<- here is package rmathbr
usepackage[a4paper]{geometry}




%% part 1 code (no variables) %%
newcommand{goesto}{xrightarrow{ntoinfty}}
SetBreakableRel{goesto}
%%-------------%%

%%part 2 code (with variables) %% (from Willie Wong)
DeclareRobustCommand{goestoarg}[2]{brokenrel{xrightarrow{#1to#2}}}
%%-------------%%

%%part 3 code (breaking – as –+)%% (from dryabov)
makeatletter
defminus@char{mathchar8704}
defplus@char{mathchar8235}
defrmathbr@selector#1{%
  defx@char{#1}%
  ifxx@charminus@chardefx@char{plus@char}fi%
  mathchoice
    {discretionary{}{hbox{$m@thdisplaystylex@char$}}{}}
    {discretionary{}{hbox{$m@thtextstylex@char$}}{}}
    {discretionary{}{hbox{$m@thscriptstylex@char$}}{}}
    {discretionary{}{hbox{$m@thscriptscriptstylex@char$}}{}}%
}
makeatother
%%-------------%%




begin{document}

$a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a+a$

$b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b-b$

$c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c=c$

$dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow dLongrightarrow d$

$egoesto egoesto egoesto egoesto egoesto egoesto egoesto egoesto egoesto egoesto egoesto egoesto e$


aasdf asdf asd fasdf asdf  aasdf asdf asd fasdf asdf asdf aasdf asd asdas $eeeeeeeeegoestoarg{a}{b} cccccccccc$ aasdf asdf asd fasdf asdf asdf aasdf asdf asd fasdf asdf asdf

$a coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b coloneqq b$

end{document}

Final note: it is also possible to disable breaking with repetition for relations/operators you do not want to be broken like that. I think the syntax is UnsetBrokenCmd{<your operator/relation name>} (restores to behaviour without rmathbr).

Correct answer by Linear Christmas on August 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP