Fixing latex generated so not to use \over. Causes latex to hang when using breqn package

9 views
Skip to first unread message

Nasser M. Abbasi

unread,
May 25, 2022, 3:47:47 PM5/25/22
to FriCAS - computer algebra system

Fricas uses very old and not recommended \over when it generates latex.
This causes modern compilers such as lualatex to hang when using dmath environment.

Could the latex be corrected to use \frac{} instead?

I do not remember if  I asked about this here before.
Here is an example

----------------------------------
>fricas
                       FriCAS Computer Algebra System
                            Version: FriCAS 1.3.7
                   Timestamp: Thu May 19 16:50:51 CDT 2022
(1) -> setSimplifyDenomsFlag(true)
(2) -> ii:=integrate(asin(x)*log(x),x);
(3) -> latex(ii)

  "{{\log \left( {{{\sqrt {{-{{x} \sp {2}}+1}}}+1}} \right)} -{\log \left( {{{\
  sqrt {{-{{x} \sp {2}}+1}}} -1}} \right)}+{{\left( {2 \  {\log \left( {x} \rig
  ht)}} -4 \right)} \  {\sqrt {{-{{x} \sp {2}}+1}}}}+{2 \  x \  {\arcsin \left(
   {x} \right)} \  {\log \left( {x} \right)}} -{2 \  x \  {\arcsin \left( {x} \
  right)}}} \over 2"
                                                                 Type: String
-----------------------------

Now compile the above latex, hangs

---- foo.tex-----
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{breqn}
\begin{document}

\begin{dmath*}
{{\log \left( {{{\sqrt {{-{{x} \sp {2}}+1}}}+1}} \right)} -{\log \left( {{{\sqrt {{-{{x} \sp {2}}+1}}} -1}} \right)}+{{\left( {2 \  {\log \left( {x} \right)}} -4 \right)} \  {\sqrt {{-{{x} \sp {2}}+1}}}}+{2 \  x \  {\arcsin \left(   {x} \right)} \  {\log \left( {x} \right)}} -{2 \  x \  {\arcsin \left( {x} \right)}}} \over 2
\end{dmath*}
\end{document}
--------------------------------

Now do 

    lualatex foo.tex


dmath is used to automatically try to break long output into separate lines which is very useful. The hangs goes away when using \[...\]   but not when using dmath environment.

Could this be fixed by next version of Fricas?

Thanks
--Nasser


Ralf Hemmecke

unread,
May 25, 2022, 4:44:49 PM5/25/22
to fricas...@googlegroups.com
On 25.05.22 21:47, 'Nasser M. Abbasi' via FriCAS - computer algebra
system wrote:
>
> Fricas uses very old and not recommended \over when it generates latex.
> This causes modern compilers such as lualatex to hang when using dmath
> environment.
>
> Could the latex be corrected to use \frac{} instead?

Well, maybe it can, but you already have everything if you run a newer
version of FriCAS (1.3.7 should be OK).

I can offer you the following:

setSimplifyDenomsFlag(true)
ii:=integrate(asin(x)*log(x),x)

print1D x ==> display((x::OutputForm)::Formatter(Format1D))
printLaTeX x ==> display((x::OutputForm)::Formatter(FormatLaTeX))
printMathJax x ==> display((x::OutputForm)::Formatter(FormatMathJax))

print1D ii
printLaTeX ii
printMathJax ii

Or if you want the output directly, without the need to call some
function, then do the following.

)set output algebra off
setFormats!([FormatMathJax])$JFriCASSupport
ii

and you get

--FORMAT:BEG:FormatMathJax
\[
\frac{\log\left(\sqrt{-{x}^{2}+1}+1\right)-\log\left(\sqrt{-{x}^{2}+1}-1\right)+\left(2\,
\log\left(x\right)-4\right)\, \sqrt{-{x}^{2}+1}+2\, x\,
\arcsin\left(x\right)\, \log\left(x\right)-2\, x\, \arcsin\left(x\right)}{2}
\]
--FORMAT:END:FormatMathJax

Note that you can actually also output other things than "\[" and "\]".
See
https://github.com/fricas/fricas/blob/master/src/algebra/fmtjfricas.spad#L168
or simply use

BOX ==> OutputBox
setDefault!(_
(s: String): BOX +-> box("\begin{dmath*}")$BOX,_
(s: String): BOX +-> box("\end{dmath*}")$BOX_
)$Formatter(FormatMathJax);

For the output of FormatLaTeX you would need
https://github.com/fricas/fricas/blob/master/src/doc/fricasmath.sty
But maybe FormatMathJax is enough for you.

Hopefully, you will find no bug. But I'd be happy if you can use that
formatting framework.

Ralf

Waldek Hebisch

unread,
May 25, 2022, 9:05:08 PM5/25/22
to 'Nasser M. Abbasi' via FriCAS - computer algebra system
On Wed, May 25, 2022 at 12:47:47PM -0700, 'Nasser M. Abbasi' via FriCAS - computer algebra system wrote:
>
> Fricas uses very old and not recommended \over when it generates latex.
> This causes modern compilers such as lualatex to hang when using dmath
> environment.
>
> Could the latex be corrected to use \frac{} instead?

Just as an explanation: FriCAS uses '\over' because it work both
in LaTeX and plain TeX.
>
> Now do
>
> lualatex foo.tex
>
> and it hags. see
> https://tex.stackexchange.com/questions/412450/why-this-latex-code-hangs-lualatex-foreign-command-over
> for reference.
>
> dmath is used to automatically try to break long output into separate lines
> which is very useful. The hangs goes away when using \[...\] but not when
> using dmath environment.

Arguably hangs you mention are bugs in corresponding packages.

> Could this be fixed by next version of Fricas?

As Ralf wrote FormatLaTeX is LaTeX only and generates '\frac'.

Since LaTeX packages you mention have trouble with '\over' it make sense
to make choice in TexFormat between '\frac' and '\over' configurable.
It even makes sense to make '\frac' a default (because plain TeX
gets much less use than in the past).

OTOH I did some experiments with using 'breqn' for line breaking
of FriCAS output and my conclusion at that time was that is is
too unreliable: it has hardcoded limits on what it can handle
and fails if output is too complicated (in fact, mainly if output
is too large). When I asked in LaTeX group answer was that basically
there is nobody to fix 'breqn'. There is an ad-hoc postprocessor that
can be run on FriCAS output which seemed to work much better than
'breqn', but still, on some output it was neccessarty to switch to
text (2D ASCII) version. To say the truth, AFAIK each way
(except possibly for 1D ASCII) of formatting FriCAS output may
fail in some cases (for multiline output FriCAS uses indentation
to show structure, but may run out of page width...).

--
Waldek Hebisch

Waldek Hebisch

unread,
Jun 17, 2022, 10:09:33 PM6/17/22
to fricas...@googlegroups.com
On Thu, May 26, 2022 at 01:57:33AM +0000, I wrote:
> On Wed, May 25, 2022 at 12:47:47PM -0700, 'Nasser M. Abbasi' via FriCAS - computer algebra system wrote:
> >
> > Fricas uses very old and not recommended \over when it generates latex.
> > This causes modern compilers such as lualatex to hang when using dmath
> > environment.
> >
> > Could the latex be corrected to use \frac{} instead?
>
> As Ralf wrote FormatLaTeX is LaTeX only and generates '\frac'.
>
> Since LaTeX packages you mention have trouble with '\over' it make sense
> to make choice in TexFormat between '\frac' and '\over' configurable.
> It even makes sense to make '\frac' a default (because plain TeX
> gets much less use than in the past).

I have now commited such change: TexFormat generates '\frac' by
default and when you do setDialect('plain) it generates '\over'.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages