6

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?

muon
  • 12,821
  • 11
  • 69
  • 88
  • Sphinx didn't raise any errors for that inclusion. it creates a page with heading (i have this in separate .rst with heading) – muon Jul 13 '17 at 13:37
  • `tex/` is outside the `source/` directory, so either move it inside or add it to your `conf.py` as an additional path for source files. – Steve Piercy Jul 14 '17 at 16:48
  • Suggest making a [MCVE](https://stackoverflow.com/help/mcve), and push it to a public repo so I can reproduce the issue. – Steve Piercy Jul 14 '17 at 20:08

1 Answers1

7

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
Luca Gibelli
  • 961
  • 12
  • 19
cosmoscalibur
  • 1,131
  • 1
  • 8
  • 17
  • thanks, i have done this before but pandoc messes up equations, tabular etc so I was hoping to import latex directly would be a less of a hassle – muon Jul 26 '17 at 16:16
  • @muon maybe you can convert first to html (using hevea, latexml or pdf2htmlex) and then use include html. – cosmoscalibur Jul 27 '17 at 04:53