简体   繁体   中英

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?

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.

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 (eg 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.

你看过Docutils吗?

If you are an Emacs user, you may find org-mode 's markup to your liking. It has very nice support for tables, coordinates well with other Emacs modes like the spreadsheet, and has good export of images to HTML. Cf. the fine manual's HTML-export section .

org-mode files are editable outside Emacs, for team members who do not use it, although the previewing and embedding of other Emacs modes can, naturally, only be done with Emacs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM