# Obtain $\TeX$ code as in StandardForm

This is a question very close related to Breaking up long equations in TeXForm. Last time, because @Adam doest not present a clear goal for this problem, as stated by Massimo Ortolano

there's no general solution to your question, especially if the splitting has to be done for a publication where clarity is of utmost importance.

I think imitate the way implemented by Mathematica in StandardForm is a reasonable result for this problem.

Consider following expression:

Sinh[b]*(-10*b*Cosh[b/2]^2*(-1 + 2*Cosh[2*b*xm])*Sin[b] +
80*b*Cosh[b/2]*Sin[b/2]*Sin[b*xm]*Sinh[b*xm] +
(-160 - 16*(-10 + b^4)*Cos[b] + (80*I)*Cos[(1 + I)*b] +
16*b^4*Cos[b*(1 - 2*xm)] - (80*I)*Cosh[(1 + I)*b] - 20*b*Sin[b] -
64*b^3*Sin[b] + (10 - 20*I)*b*Sin[(1 + I)*b] + 40*b*Sin[b*(1 - 2*xm)] -
(20*I)*b*Sin[b*((1 - I) - 2*xm)] + (20*I)*b*Sin[b*((1 + I) - 2*xm)] +
40*b*Sin[2*b*xm] + (20 - 10*I)*b*Sinh[(1 + I)*b] -
4*b*(10 - 10*Cos[b] + 4*b^3*Sin[b] - 10*Sin[b]*Sinh[b])*Sinh[2*b*xm])/4) +
(Cosh[b]*(b*Cosh[b*xm]^2*(20 - 20*Cos[b] + 2*Sin[b]*(4*b^3 + 10*Sinh[b])) +
(-40*b + 100*b*Cos[b] - (10 + 20*I)*b*Cos[(1 + I)*b] -
60*b*Cos[b*(1 - 2*xm)] + 10*b*Cos[b*((1 - I) - 2*xm)] +
10*b*Cos[b*((1 + I) - 2*xm)] - (10 - 20*I)*b*Cosh[(1 + I)*b] +
240*Sin[b] - 16*b^4*Sin[b] - 40*Sin[(1 + I)*b] + (40*I)*Sinh[(1 + I)*b] -
320*b*Sin[b/2]*Sin[b*xm]*Sinh[b/2]*Sinh[b*xm] +
4*b*(10 - 10*Cos[b] + 4*b^3*Sin[b] + 10*Sin[b]*Sinh[b])*Sinh[b*xm]^2 -
20*b*(-3 + Cosh[b])*Sin[b]*Sinh[2*b*xm])/2 -
10*Cosh[b/2]^2*(2*b*Cos[b] - 2*b*Cos[b*(1 - 2*xm)] +
2*Sin[b]*(4 + b*Sinh[2*b*xm]))))/2


By adjusting the width of the window, several ways to break the expression is given by Mathematica. The question is whether it is possible to obtain $TeX$ codes equivalent to these StandardForm outputs.

• Line breaking is done "on the fly" by FrontEnd, its effects are not visible on box level, on which conversion to $TeX$ occurs. I don't know whether there's any way of accessing FrontEnd's algorithms. I'm afraid only way to achieve what you want, is to re-implement line breaking on box level from scratch. Best thing we have for formatting on box level is Leonid's CodeFormatter, but as far as I know it mostly pretty-prints "code" not "mathematical expressions". Jun 17 '15 at 18:37
• @jkuczm do you have any idea on how the FrontEnd break the lines. I think it is better implemented than breqn latex package. Jun 18 '15 at 8:06
• Unfortunately all I know is what can be gathered from details of Line Breaking options especially "Details" section of LinebreakAdjustments which gives general overview of how it works and how to customize it, but not much on how it's implemented. Jun 18 '15 at 12:46