Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output formatted text (including source code) as LaTeX, PDF and HTML

I am editing a lot of documents in latex that consist of code listings and are currently output to pdf.

Since I am working in teams on those documents, I often need to manually integrate changes done by group members to the latex source.

Most of the group members do not know latex, so I would like to have a means to enable them to do the document formatting in a style maybe similar to markdown.

Since the latex documents consist of figures, have references and use the lslisting package, I am wondering if it would be possible to map these specific areas to a simple markdown style syntax.

Workflow Example:

  • Edit file in Markdown (or similar)
    • tag sections
    • tag code areas
    • tag figures
    • tag references
  • convert to latex
    • automatically convert tags
  • output
    • pdf
    • html

Would it somehow be possible to achieve such a workflow? Maybe there are already solutions to my specific workflow?

like image 592
jottr Avatar asked Jan 19 '11 19:01

jottr


3 Answers

Here is an example for Docutils.

Title
=====

Section
-------

.. _code:

Code area::

  #include <iostream>
  int main() {
    std::cout << "Hello World!" << std::endl;
  }

.. figure:: image.png

   Caption for figure

A reference to the code_


Another section
---------------

- Itemize
- lists

#. Enumerated
#. lists

+-----+-----+
|Table|Table|
+-----+-----+
|Table|Table|
+-----+-----+

Save that as example.rst. Then you can compile to HTML:

rst2html example.rst example.html

or to LaTeX:

rst2latex example.rst example.tex

then compile the resulting LaTeX document:

pdflatex example.tex
pdflatex example.tex  # twice to get the reference right

A more comprehensive framework for generating documents from multiple sources is Sphinx, which is based on Docutils and focuses on technical documentation.

like image 119
Philipp Avatar answered Nov 17 '22 06:11

Philipp


You should look at pandoc (at least if I understand your question correctly). It can convert between multiple formats (tex, pdf, word, reStructuredText) and also supports extended versions of markdown syntax to handle more complex issues (e.g. inserting header information in html).

With it you can mix markdown and LaTeX, and then compile to html, tex and pdf. You can also include bibtex references from an external file.

Some examples (from markdown to latex and html):

pandoc -f markdown -t latex infile.txt -o outfile.tex
pandoc -f markdown -t html infile.txt -o outfile.html

To add your own LaTex template going from markdown to pdf, and a bibliography:

 pandoc input.text --template=FILE --bibliography refs.bib -o outfile.pdf

It is really a flexible and awesome program, and I'm using it much myself.

like image 37
fileunderwater Avatar answered Nov 17 '22 08:11

fileunderwater


Have you looked at Docutils?

like image 1
Matthew Leingang Avatar answered Nov 17 '22 07:11

Matthew Leingang