【问题标题】:RuntimeError: latex was not able to process the following string: '_auto'RuntimeError:latex 无法处理以下字符串:'_auto'
【发布时间】:2018-06-07 06:15:57
【问题描述】:

谁会关心我的问题,

我在 jupyter notebook 上执行 LIGO 团队构建的 python 代码时遇到了问题。当我尝试在没有jupyter notebook环境的情况下执行以下简单代码时,可以得到正确的输出和附图。

++++++++++++++++++++++++++++++++++++

from gwpy.timeseries import TimeSeries
from numpy import random
series = TimeSeries(random.random(1000), sample_rate=100, unit='m')
plot = series.plot()
plot.show()

++++++++++++++++++++++++++++

Generation of random plots

但是当我在 jupyter notebook 中应用以下类似的 python 代码时:

++++++++++++++++++

`%matplotlib inline`

%config InlineBackend.figure_format = 'retina'
from gwpy.timeseries import TimeSeries
from numpy import random
series = TimeSeries(random.random(1000), sample_rate=100, unit='m')
plot = series.plot()

++++++++++++++++++

我得到了与 Latex 相关的运行时错误。 由于如果我不使用 jupyter 可以得到正确的输出,我推测问题是由于将绘图转换为在笔记本环境中呈现的。 我尝试检查与latex相关的相关运行时错误并通过Macports安装软件包(例如dvipng,texlive-latex-extra和texlive-fonts-recommended)或在我的机器上重新安装MacTeX,但问题仍然存在。 这是我在 jupyter notebook 上获得的警告和错误消息。


RuntimeError                        Traceback (most recent call last)
/Users/lupin/Library/Python/2.7/lib/python/site-packages/IPython/core/formatters.pyc in __call__(self, obj)

    332                 pass

    333             else:

--> 334                 return printer(obj)

    335             # Finally look for special method names

    336             method = get_real_method(obj, self.print_method)

/Users/lupin/Library/Python/2.7/lib/python/site-packages/IPython/core/pylabtools.pyc in <lambda>(fig)

    247         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))

    248     if 'retina' in formats or 'png2x' in formats:

--> 249         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

    250     if 'jpg' in formats or 'jpeg' in formats:

    251         jpg_formatter.for_type(Figure, lambda fig: print_figure(fig, 'jpg', **kwargs))

/Users/lupin/Library/Python/2.7/lib/python/site-packages/IPython/core/pylabtools.pyc in retina_figure(fig, **kwargs)

    137 def retina_figure(fig, **kwargs):

    138     """format a figure as a pixel-doubled (retina) PNG"""

--> 139     pngdata = print_figure(fig, fmt='retina', **kwargs)

    140     # Make sure that retina_figure acts just like print_figure and returns

    141     # None when the figure is empty.

/Users/lupin/Library/Python/2.7/lib/python/site-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)

    129 

    130     bytes_io = BytesIO()

--> 131     fig.canvas.print_figure(bytes_io, **kw)

    132     data = bytes_io.getvalue()

    133     if fmt == 'svg':

/Library/Python/2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)

   2212                     **kwargs)

   2213                 renderer = self.figure._cachedRenderer

-> 2214                 bbox_inches = self.figure.get_tightbbox(renderer)

   2215 

   2216                 bbox_artists = kwargs.pop("bbox_extra_artists", None)

/Library/Python/2.7/site-packages/matplotlib/figure.pyc in get_tightbbox(self, renderer)

   2188         for ax in self.axes:

   2189             if ax.get_visible():

-> 2190                 bb.append(ax.get_tightbbox(renderer))

   2191 

   2192         if len(bb) == 0:

/Library/Python/2.7/site-packages/matplotlib/axes/_base.pyc in get_tightbbox(self, renderer, call_axes_locator)

   4168             bb.append(self._right_title.get_window_extent(renderer))

   4169 

-> 4170         bb_xaxis = self.xaxis.get_tightbbox(renderer)

   4171         if bb_xaxis:

   4172             bb.append(bb_xaxis)

/Library/Python/2.7/site-packages/matplotlib/axis.pyc in get_tightbbox(self, renderer)

   1158         for a in [self.label, self.offsetText]:

   1159             if a.get_visible():

-> 1160                 bb.append(a.get_window_extent(renderer))

   1161 

   1162         bb.extend(ticklabelBoxes)

/Library/Python/2.7/site-packages/matplotlib/text.pyc in get_window_extent(self, renderer, dpi)

    920             raise RuntimeError('Cannot get window extent w/o renderer')

    921 

--> 922         bbox, info, descent = self._get_layout(self._renderer)

    923         x, y = self.get_unitless_position()

    924         x, y = self.get_transform().transform_point((x, y))

/Library/Python/2.7/site-packages/matplotlib/text.pyc in _get_layout(self, renderer)

    307                 w, h, d = renderer.get_text_width_height_descent(clean_line,

    308                     
                                    self._fontproperties,
--> 309                                                         ismath=ismath)

    310             else:

    311                 w, h, d = 0, 0, 0

/Library/Python/2.7/site-packages/matplotlib/backends/backend_agg.pyc in get_text_width_height_descent(self, s, prop, ismath)

    230             fontsize = prop.get_size_in_points()

    231             w, h, d = texmanager.get_text_width_height_descent(

--> 232                 s, fontsize, renderer=self)

    233             return w, h, d

    234 

/Library/Python/2.7/site-packages/matplotlib/texmanager.pyc in get_text_width_height_descent(self, tex, fontsize, renderer)

    499         else:

    500             # use dviread. It sometimes returns a wrong descent.

--> 501             dvifile = self.make_dvi(tex, fontsize)

    502             with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:

    503                 page = next(iter(dvi))

/Library/Python/2.7/site-packages/matplotlib/texmanager.pyc in make_dvi(self, tex, fontsize)

    363                 self._run_checked_subprocess(

    364                     ["latex", "-interaction=nonstopmode", "--halt-on-error",

--> 365                      texfile], tex)

    366             for fname in glob.glob(basefile + '*'):

    367                 if not fname.endswith(('dvi', 'tex')):

/Library/Python/2.7/site-packages/matplotlib/texmanager.pyc in _run_checked_subprocess(self, command, tex)

    342                     prog=command[0],

    343                     tex=tex.encode('unicode_escape'),

--> 344                     exc=exc.output.decode('utf-8')))

    345         _log.debug(report)

    346         return report

RuntimeError: latex was not able to process the following string:
'_auto'

Here is the full report generated by latex:

This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/MacPorts 2017_4) (preloaded format=latex)
 restricted \write18 enabled.

entering extended mode
(/Users/lupin/.matplotlib/tex.cache/1de80ee53f095837776b678f34112ba4.tex
LaTeX2e <2017-04-15>
Babel <3.10> and hyphenation patterns for 3 language(s) loaded.

(/opt/local/share/texmf-texlive/tex/latex/base/article.cls

Document Class: article 2014/09/29 v1.4h Standard LaTeX document class

(/opt/local/share/texmf-texlive/tex/latex/base/size10.clo))

(/opt/local/share/texmf-texlive/tex/latex/type1cm/type1cm.sty)

(/opt/local/share/texmf-texlive/tex/latex/base/textcomp.sty

(/opt/local/share/texmf-texlive/tex/latex/base/ts1enc.def))

(/opt/local/share/texmf-texlive/tex/latex/geometry/geometry.sty

(/opt/local/share/texmf-texlive/tex/latex/graphics/keyval.sty)

(/opt/local/share/texmf-texlive/tex/generic/oberdiek/ifpdf.sty)

(/opt/local/share/texmf-texlive/tex/generic/oberdiek/ifvtex.sty)

(/opt/local/share/texmf-texlive/tex/generic/ifxetex/ifxetex.sty)

Package geometry Warning: Over-specification in `h'-direction.
    `width' (5058.9pt) is ignored.


Package geometry Warning: Over-specification in `v'-direction.
    `height' (5058.9pt) is ignored.

) (./1de80ee53f095837776b678f34112ba4.aux)

(/opt/local/share/texmf-texlive/tex/latex/base/ts1cmr.fd)

*geometry* driver: auto-detecting

*geometry* detected driver: dvips

! Missing $ inserted.

<inserted text> 
                $
l.13 \fontsize{20.000000}{25.000000}{\rmfamily _
                                                auto}

No pages of output.

Transcript written on 1de80ee53f095837776b678f34112ba4.log.

谁能提供一些解决这个问题的建议?

【问题讨论】:

    标签: python-2.7 jupyter-notebook


    【解决方案1】:

    latex 中的'_' 图例表示下标,译者无法从'$$' 中识别出来,将'_auto' 替换为'-auto' 可能会有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-21
      • 1970-01-01
      • 2015-09-25
      • 2017-06-06
      • 2020-02-13
      相关资源
      最近更新 更多