Git Product home page Git Product logo

mlabtex's Introduction

mlabtex

DOI PyPI version Build Status Coverage Status Documentation Status Code style: black

Purpose

mlabtex provides a renderer for latex code in mayavi.

Installation

pip install mlabtex

Functions

The following functions are provided

  • render_latex -- A renderer for latex-code to produce image files.
  • mlabtex -- A renderer for latex code in mayavi.
  • mlabimg -- A renderer for image files in mayavi.

Dependencies

For rendering

Example

You can use it like the mlab.surf routine:

from mayavi import mlab
from mlabtex import mlabtex

text = (
    r'Sebastian M\"uller, '
    + r'$f(x)=\displaystyle\sum_{n=0}^\infty '
    + r'f^{(n)}(x_0)\cdot\frac{(x-x_0)^n}{n!}$'
)
tex = mlabtex(
    0., 0., 0.,
    text,
    color=(0., 0., 0.),
    orientation=(30., 0., 0.),
    dpi=1200,
)
mlab.axes()
mlab.show()

Latex in Mayavi

Copyright Sebastian Mueller 2019

mlabtex's People

Contributors

muellerseb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lschueler

mlabtex's Issues

orient_to_camera

It appears that mlabtex does not have the orient_to_camera option that is the default in mlab.text3d so I guess this is a feature request, though possibly a difficult one. The feature is important to retain visibility when interactively rotating a scene, such as for latex labels to identify solids or sets of coordinate axes. Thanks.

01_tex not running, \displaystyle problem

pdf version:
01_tex_bug_report.pdf

After installing mlabtex, 01_tex.py did not run successfully. There is a long error message (below) that in part
refers to \displaystyle. If \displaystyle is removed from 01_tex.py and rerun the program runs to completion with the
following figure output (size and orientation adjusted for clarity):

01_tex_without_displaystyle

This looks very different from the one distributed with the package where " is rendered correctly and the fonts are
different (looks like a Helvetica for the text and a Computer Modern for the math):

image

The OS is Windows 10 and the Anaconda IDE is being used with Python 3.7.7, Sympy 1.6.1, Matplotlib 3.2.2, and Mayavi 4.7.1.

Would appreciate any help in getting this to work, hopefully it's something simple. Thanks.

---------------------------------- Error Message -----------------------------------------------------------------------
runfile('C:/Users/hl3-home/Dropbox/Python/01_tex.py', wdir='C:/Users/hl3-home/Dropbox/Python')
Traceback (most recent call last):

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\mlabtex\core.py", line 236, in render_latex
render_latex_sympy(text, path, color, dpi, output)

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\mlabtex\core.py", line 195, in render_latex_sympy
"Transparent",

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\sympy\printing\preview.py", line 149, in preview
raise SystemError("Unrecognized viewer: %s" % viewer)

SystemError: Unrecognized viewer: file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\matplotlib\mathtext.py", line 2581, in parse
result = self._expression.parseString(s)

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\pyparsing.py", line 1955, in parseString
raise exc

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\matplotlib\mathtext.py", line 2752, in unknown_symbol
raise ParseFatalException(s, loc, "Unknown symbol: %s" % c)

ParseFatalException: Unknown symbol: \displaystyle

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\mlabtex\core.py", line 239, in render_latex
render_latex_mpl(text, path, color, dpi, output)

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\mlabtex\core.py", line 110, in render_latex_mpl
width, height, depth, _, _ = parser.parse(text, dpi=72, prop=prop)

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\matplotlib\mathtext.py", line 3354, in parse
box = self._parser.parse(s, font_output, fontsize, dpi)

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\matplotlib\mathtext.py", line 2586, in parse
str(err)]))

ValueError:
f(x)=\displaystyle\sum_{n=0}^\infty f^{(n)}(x_0)\cdot\frac{(x-x_0)^n}{n!}
^
Unknown symbol: \displaystyle, found '' (at char 5), (line:1, col:6)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Users\hl3-home\Dropbox\Python\01_tex.py", line 18, in
dpi=1200

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\mlabtex\core.py", line 431, in mlabtex
render_latex(text, path=pngfile.name, color=color, dpi=dpi)

File "C:\Users\hl3-home\Anaconda3\envs\Python37\lib\site-packages\mlabtex\core.py", line 247, in render_latex
+ os.linesep

RenderError: Mlabtex: Could not render the latex-code...
Unrecognized viewer: file

f(x)=\displaystyle\sum_{n=0}^\infty f^{(n)}(x_0)\cdot\frac{(x-x_0)^n}{n!}
^
Unknown symbol: \displaystyle, found '' (at char 5), (line:1, col:6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.