15
$\begingroup$

I want to use math text in Blender.

For example, I would like to have fractions (A/B) where the letter A is on top of letter B and the division line is horizontal. I also would like to move this fraction around by animations just as I can do it with any other object.

I found here that writing mathematical formulas using latex syntax should be no problem. But I dont really understand how to use it. If I simply write this in text mode, then it doesn't work:enter image description here

So how does it work?

$\endgroup$
3
  • 3
    $\begingroup$ The math tags that you link to are about adding formulas to the wiki pages - as part of the documentation. $\endgroup$
    – sambler
    Commented Jan 30, 2017 at 17:13
  • 4
    $\begingroup$ A friend and I recently made a Blender add-on called latex2blender that enables users to write LaTeX in Blender. Here is the GitHub wiki page for the add-on: github.com/ghseeli/latex2blender/wiki $\endgroup$
    – peterkj
    Commented Jan 22, 2020 at 0:19
  • 1
    $\begingroup$ @peterkj Thanks for writing this add-on! May I suggest you write an answer to bring more attention to your work. $\endgroup$
    – cjorssen
    Commented Jan 28, 2022 at 11:57

5 Answers 5

20
$\begingroup$

Here is how I would do it

  1. Wrap your expression inside a LaTeX document

    \documentclass{standalone}
    \usepackage{lmodern} %or whatever you like 
    \usepackage[intlimits]{amsmath}
    \usepackage{amsthm, amssymb, amsfonts} %Useful stuff
    \begin{document}
    $ <your expression> $
    \end{document}
    
  2. Pipe that to pdflatex, or save it to expression.tex

  3. If you used a pipe:

    pdftocairo -svg texput.pdf expression.svg
    

    If you used a temporary file:

    pdftocairo -svg expression.pdf expression.svg
    
  4. Import expression.svg into blender

  5. Remove temporary files created by pdflatex.

This procedure can be converted into an addon. The dirty way of doing it is to modify the svg importer to run steps 1-3. The correct way is to use Python bidings for Poppler to load the pdf directly.

Test case:

\documentclass{standalone}
\usepackage{lmodern} %or whatever you like 
\usepackage[intlimits]{amsmath}
\usepackage{amsthm, amssymb, amsfonts} %Useful stuff
\begin{document}
$\displaystyle\mathcal{F}\left[f\right](\xi)=\int_{-\infty}^\infty   f(x)\exp(\mathrm{i\xi x})\,\mathrm{d}x$
\end{document}

Result (after some tweeks [curve to mesh, remesh, smooth]:

fourier

$\endgroup$
9
$\begingroup$

You can get math into blender following these steps

LibO Math

  • Export to pdf File > Export
  • Open the pdf with inkscape

  • Delete the outer border

Inkscape

  • Select the equation
  • Go to Document Properties CtrlShiftD or File > Document Properties and press Resize page to drawing or selection. (This step is optional, however it helps insert the equation at the center of the blender scene and sets the origin near the equation, but you can do all this later in blender)

Document Properties

  • Path > Object to Path

  • Save as .svg

  • Go to Blender and import the .svg.

Equations in blender!

In my case it works like that but I assume that there might be a need to ungroup before converting to paths. If you see that you get only lines but not digits and other text into blender, ungroup the equation CtrlU or CtrlShiftG or right click and then Ungroup or ungroup or Object > Ungroup (There are a lot ways to ungroup 😊 ) before converting to paths.

$\endgroup$
6
$\begingroup$

From what I can see, that link is not a guide to using Latex in Blender, it is a guide on how to write Latex in the Blender Wiki (the old manual). It is not saying that Latex can be written in Blender. The page you linked to is in the Meta category of the Blender Wiki, that is, support pages about the creation of the Blender Wiki itself.

As far as I know, it is not possible to write that type of mathematical syntax in Blender unless you want to write each letter/number/symbol as an individual text object and place them manually.

Another option may be to find a different program that does support Latex and export to a format that is compatible with Blender ie. SVG, but even then, it would not be editable within Blender itself.

$\endgroup$
5
$\begingroup$

In order to bring the comment more visible, I can highly recommend the great package latex2blender. It's really to install, and really easy to use & powerful (e.g. you can add your own preambule, use lualatex/…, custom material & orientation…):

enter image description here

$\endgroup$
1
$\begingroup$

Trying to do something similar, I found a path similar to but different from user877329's answer. There's also a link to some code that takes tex files and produces svgs.

You can create a tex file, convert it to a dvi file, and convert that to an svg, which blender can import via bpy.ops.import_curve.svg(). The result will be a collection of curve objects rather than text objects, so you'll have to do any text-related styling from the tex file itself, but if you're working with scripts, that might be easier anyway.

As a starting point for doing this in python, I used functions defined around line 300 of this github file (related to quite a nice math animation YT channel, incidentally). The functions themselves just pass commands to other utilities that do the actual work, but they show a process that could be used to get from tex to svg. tex_to_svg() is the core function, from which you can follow the flow to other functions as you make sense of things and adapt to your needs.

The needed utilities are pdfTex (for tex->dvi) and dvisvgm (for dvi->svg).

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .