opencollab / jlatexmath

A Java API to render LaTeX
Other
513 stars 109 forks source link

How to render "closed square roots"? #60

Open coronel-kittycannon opened 5 years ago

coronel-kittycannon commented 5 years ago

This article describes how it is possible in LaTeX to render a "closed square root". I would like to draw one myself, but the code provided does not work. I suppose I am doing something wrong, because I literally started using this library today.

This is the LaTeX code provided by the article

% New definition of square root:
% it renames \sqrt as \oldsqrt
\let\oldsqrt\sqrt
% it defines the new \sqrt in terms of the old one
\def\sqrt{\mathpalette\DHLhksqrt}
\def\DHLhksqrt#1#2{%
\setbox0=\hbox{$#1\oldsqrt{#2\,}$}\dimen0=\ht0
\advance\dimen0-0.2\ht0
\setbox2=\hbox{\vrule height\ht0 depth -\dimen0}%
{\box0\lower0.4pt\box2}}

image

This is the result from the article. I am thinking I could just do something like...

TeXFormula fx = new TeXFormula("% New definition of square root:\r\n" + 
                "% it renames \\sqrt as \\oldsqrt\r\n" + 
                "\\let\\oldsqrt\\sqrt\r\n" + 
                "% it defines the new \\sqrt in terms of the old one\r\n" + 
                "\\def\\sqrt{\\mathpalette\\DHLhksqrt}\r\n" + 
                "\\def\\DHLhksqrt#1#2{%\r\n" + 
                "\\setbox0=\\hbox{$#1\\oldsqrt{#2\\,}$}\\dimen0=\\ht0\r\n" + 
                "\\advance\\dimen0-0.2\\ht0\r\n" + 
                "\\setbox2=\\hbox{\\vrule height\\ht0 depth -\\dimen0}%\r\n" + 
                "{\\box0\\lower0.4pt\\box2}}");

...but it doesn't work. Please help me.