Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sphinx: Including .tex file via raw:: latex

I want to include latex doc in sphinx. sphinx html build does not include the latex file linked using .. raw:: latex directive. I have

this is my dir structure

docs/
    source/
        importlatex.rst
        index.rst

    build/
    tex/
       texfile.tex

index.rst looks like

Welcome to documentation!
=========================

Contents:

.. toctree::
   :maxdepth: 2

   icnludelatex
   and-other-stuff

icnludelatex.rst looks like:

Include Latex
=============

.. raw:: latex
    :file: ../tex/texfile.tex

this reference gives example for including html

.. raw:: html
    :file: inclusion.html

why is this happening?

like image 434
muon Avatar asked Jul 12 '17 17:07

muon


1 Answers

When you use a raw directive, the block is only interpreted by the writer associated. Example, .. raw:: latex works if you generate LaTeX but it is invisible to HTML.

What you need is a parser for LaTeX, but in a fast search, I only find parsers for markdown (recommonmark) and jupyter notebook (nbsphinx).

Maybe, a quick and dirty solution is to convert your latex doc to rst using pandoc (you may lose some formatted text).

pandoc -s texfile.tex -o texfile.rst

and then use the include directive in your icnludelatex.rst.

.. include:: texfile.rst
like image 60
cosmoscalibur Avatar answered Nov 03 '22 23:11

cosmoscalibur