Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I asked about this in the TeX chat. It seems Mathematica generate invalid Latex in this example.

ode = D[y[x], x] - (y[x]^2 + 1)/(Abs[y[x] + (1 + y[x])^(1/2)]*(1 + x)^(3/2));

The output is

y'(x)-\frac{y(x)^2+1}{(x+1)^{3/2} \left\left| y(x)+\sqrt{y(x)+1}\right\right| }

Using \left\left is illegal. TeXLive 2014 will not compile it. MWE


y'(x)-\frac{y(x)^2+1}{(x+1)^{3/2} \left\left| y(x)+\sqrt{y(x)+1}\right\right| }



 pdflatex foo.tex

! Missing delimiter (. inserted).
<to be read again> 
l.7 ...eft\left| y(x)+\sqrt{y(x)+1}\right\right| }


Just wanted to confirm with others if this is a bug before send email to unless someone finds a smart fix or an option to solve this.

V9.01 and V10.


If any one gets such a case, the fix in this example is to simply remove the extra \left at the outers. Like this


    y'(x)-\frac{y(x)^2+1}{(x+1)^{3/2} \left| y(x)+\sqrt{y(x)+1}\right| }

Compiles now ok. The output is

Mathematica graphics

fyi, just send an email to as well. Experts in Latex at TeX forum confirmed the code generated by Mathematica is wrong.

share|improve this question
The same here using on Linux. – Sigur Jul 15 '14 at 1:33
The problematic part seems to be that inside Abs is an expression which possibly requires scaled boundaries, because the expression is too large. Therefore, this works TeXForm[Abs[x + 1]] while this TeXForm[Abs[x + 1/2]] is introducing the extra left/right pair. Can find more notation like Abs and Norm that surround an expression? – halirutan Jul 15 '14 at 1:46
up vote 14 down vote accepted

Why we're getting this buggy result

In process of conversion to $\TeX$, whenever Mathematica encounters "something delimited" i.e. RowBox with something surrounded with Strings matching:

"(" | "[" | "\[LeftModified]" | "\[LeftDoubleBracket]" | "{" | "\[Piecewise]" | "\[LeftFloor]" | "\[LeftCeiling]" | "\[LeftAngleBracket]" | "\[LeftSkeleton]" | "«" | "\[LeftBracketingBar]" | "\[LeftDoubleBracketingBar]" | ")" | "]" | "\[RightModified]" | "\[RightDoubleBracket]" | "}" | "\[RightFloor]" | "\[RightCeiling]" | "\[RightAngleBracket]" | "\[RightSkeleton]" | "»" | "\[RightBracketingBar]" | "\[RightDoubleBracketingBar]" | "/" | "\\" | "|" | "\[VerticalSeparator]" | "||"`

then it tests, whether those delimited boxes can potentially result in something higher then line height, using System`Convert`TeXFormDump`DelimiterBoxQ function.

If System`Convert`TeXFormDump`DelimiterBoxQ returns False, then "ordinary translation" to $\TeX$ occurs and delimiters are converted using System`Convert`TeXFormDump`maketex function, which for Abs TraditionalForm delimiters: "\[LeftBracketingBar]", "\[RightBracketingBar]" returns "\\left| " and "\\right| " respectively.

That's why we get:

Abs[x + 1]//TeXForm
(* \\left| x+1\\right| *)

If System`Convert`TeXFormDump`DelimiterBoxQ returns, True then delimiters are converted using System`Convert`TeXFormDump`InsertDelimiters function which adds \\left or \\right to result of conversion of delimiter with System`Convert`TeXFormDump`$TeXDelimiterReplacements rules.

System`Convert`TeXFormDump`$TeXDelimiterReplacements contains replacement rules for delimiters like "\[LeftAngleBracket]" -> {"\\langle "}. Among them, for unknown reason, two pairs of $\TeX$ delimiters contain additional "\\left" and "\\right" commands:

System`Convert`TeXFormDump`$TeXDelimiterReplacements // TableForm
    \[LeftBracketingBar] -> {\left| }
    \[LeftDoubleBracketingBar] -> {\left\| }
    \[RightBracketingBar] -> {\right| }
    \[RightDoubleBracketingBar] -> {\right\| }

In case of "\[LeftBracketingBar]", "\[LeftDoubleBracketingBar]" and their right counterparts, System`Convert`TeXFormDump`InsertDelimiters function adds additional \\left and \\right to delimiters that already have them from System`Convert`TeXFormDump`$TeXDelimiterReplacements rules.

That's why we get:

Abs[x + 1/2]//TeXForm
(* \left\left| x+\frac{1}{2}\right\right| *)

This bug was introduced in Mathematica version 9. In version 8 there are no additional \\left and \\right commands neither in System`Convert`TeXFormDump`$TeXDelimiterReplacements rules, nor in System`Convert`TeXFormDump`maketex function.

How to fix this bug

Fixing this bug is easy, we just need to patch System`Convert`TeXFormDump`$TeXDelimiterReplacements rules:

System`Convert`TeXFormDump`$TeXDelimiterReplacements =
    System`Convert`TeXFormDump`$TeXDelimiterReplacements /. {
        "\\left| " | "\\right| " -> "|",
        "\\left\\| " | "\\right\\| " -> "\\| "

Now we get correct $\TeX$ code:

Abs[x] // TeXForm
(* \left| x\right| *)

Abs[x + 1/2] // TeXForm
(* \left|x+\frac{1}{2}\right| *)

D[y[x], x] - (y[x]^2 + 1)/(Abs[y[x] + (1 + y[x])^(1/2)]*(1 + x)^(3/2)) // TeXForm
(* y'(x)-\frac{y(x)^2+1}{(x+1)^{3/2} \left|y(x)+\sqrt{y(x)+1}\right|} *)
share|improve this answer

Your Answer


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.