question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot make linebreaks in mathematical formula using KaTeX

See original GitHub issue

I’m trying to create an Android vidget that shows mathematical formula, using KaTeX library and WebView. The problem is that I cannot configure it to automatical wrapping of formulae, that are bigger, than screen.

My java code:

    WebView webView = new WebView(SpaceActivity.this);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    webView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    webView.setPadding(2, valueViewer.getTextPadding(), 2, valueViewer.getTextPadding());
    String html = "<!DOCTYPE html>\n" +
            "<html>\n" +
            "    <head>\n" +
            "        <meta charset=\"UTF-8\">\n" +
            "        <title>Auto-render test</title>\n" +
            "        <link rel=\"stylesheet\" type=\"text/css\" href=\"file:///android_asset/katex/katex.min.css\">\n" +
            "        <script type=\"text/javascript\" src=\"file:///android_asset/katex/katex.min.js\"></script>\n" +
            "        <script type=\"text/javascript\" src=\"file:///android_asset/katex/contrib/auto-render.min.js\"></script>\n" +
            "    </head>\n" +
            "    <body>\n" +
            "        " + expression + // variable, containing formula in TeX-format
            "        <script>\n" +
            "          renderMathInElement(\n" +
            "              document.body\n" +
            "          );\n" +
            "        </script>\n" +
            "    </body>\n" +
            "</html>";
    webView.getSettings().setSupportZoom(true);
    webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", null);

Earlier I used MathJax library, but it is much slower than KaTeX, plus, when I give new formula to MathJax-related vidget, it flashes and diddles, making unbeautiful performance.

How can I configure KaTeX for line wrapping?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
edemainecommented, Jun 24, 2019

Closing this, as it’s represented by other requests for automatic line breaking in display math (e.g. #1023), and discussion seems to have ended. If you need further help, feel free to post again.

0reactions
edemainecommented, Jan 8, 2019

It wraps on katex.org if you turn off displayStyle in the settings menu (click on the gear). This is the equivalent of using $ instead of $$.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does \\ not return a new line in an equation?
Both equation and equation* do not allow multi lined expressions. Use aligned from amsmath , inside equation* to break in to many lines....
Read more >
How can I have linebreaks in my long LaTeX equations?
I would question if you really want to do that. Multi-line equations will be very difficult to read. Is it possible to break...
Read more >
Common Issues
KaTeX does not support the align environment because LaTeX doesn't support align in math mode. The aligned environment offers the same functionality but...
Read more >
Solved: Newline within Latex/Katex editing mode
Yes, I am aware that "\\" will insert a newline in the rendered math. I am asking to insert newlines in the Latex...
Read more >
LaTeX Error: There's no line here to end
In the above example, a line-break has been inserted with no text before it. LaTeX doesn't know what to do since it cannot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found