latex2markdown


Namelatex2markdown JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/ajtulloch/LaTeX2Markdown
SummaryAn AMS-LaTeX compatible converter that maps a subset of LaTeX to Markdown/MathJaX.
upload_time2012-04-03 05:15:03
maintainerNone
docs_urlNone
authorAndrew Tulloch
requires_pythonNone
licenseUNKNOWN
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            LaTeX2Markdown
==============

An `AMS-LaTeX <http://en.wikipedia.org/wiki/AMS-LaTeX>`_ compatible
converter from (a subset of) `LaTeX <http://www.latex-project.org/>`_ to
`MathJaX <http://www.mathjax.org/>`_ compatible
`Markdown <http://daringfireball.net/projects/markdown/>`_.

Anyone who writes LaTeX documents using the AMS-LaTeX packages
(``amsmath``, ``amsthm``, ``amssymb``) and wants to convert these
documents to Markdown format to use with MathJaX. These Markdown files
can then be easily added to any web platform - Jekyll blogs, Wordpress,
basic HTML sites, etc.

In short, if you seek to use MathJaX to view your LaTeX documents
online, then you might be interested in this.

Demonstration
-------------

Check out
`tullo.ch/projects/LaTeX2Markdown <http://tullo.ch/projects/LaTeX2Markdown>`_
for a live demonstration of the converter.

Getting Started
---------------

Installation
~~~~~~~~~~~~

The project is available on PyPI, so getting it is as simple as using

::

    pip install latex2markdown

or

::

    easy_install latex2markdown

Usage
~~~~~

The utility can be called from the command line, or from within a Python
script.

For the command line, the syntax to convert a LaTeX file to a Markdown
file is as follows:

::

    python -m latex2markdown path/to/latex/file path/to/output/markdown/file

For example, to compile a LaTeX file ``sample.tex`` into a Markdown file
``sample.md``, call

::

    python -m latex2markdown sample.tex sample.md

To use it within a Python script (to extend it, modify output, etc.),
you can use it as follows:

::

    import latex2markdown
    with open("latex_file.tex", "r") as f:
        latex_string = f.read()

    l2m = latex2markdown.LaTeX2Markdown(latex_string)

    markdown_string = l2m.to_markdown()

    with open("markdown_file.md", "w") as f:
        f.write(markdown_string)

Finally, add the following snippet to your HTML when loading this
document.

::

    <script type="text/x-mathjax-config">
        MathJax.Hub.Config({
            extensions: ["tex2jax.js", "AMSmath.js"],
            jax: ["input/TeX", "output/HTML-CSS"],
            tex2jax: {
                inlineMath: [ ['$','$'], ["\\(","\\)"] ],
                displayMath: [ ['$$','$$'], ["\[","\]"] ],
                processEscapes: true
            },
        });
    </script>
    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>

For a working example, have a look at the source of the
`tullo.ch <http://tullo.ch>`_ homepage
`here <https://github.com/ajtulloch/ajtulloch.github.com>`_.

Why not use Pandoc?
-------------------

`Pandoc <http://johnmacfarlane.net/pandoc/%20##%20Who%20should%20use%20this?>`_
is an excellent document converter for less complex LaTeX documents.
Indeed, I've used it to convert this README document to a reST version
for use on PyPI.

Unfortunately, it is not designed to deal with documents that use the
AMSTeX extensions - which include the theorem, lemma, proof, and
exercise environments that are heavily used for typesetting papers,
lecture notes, and other documents.

As neither Pandoc nor MathJaX can deal with these documents, I hacked
together a set of regular expressions that can convert a subset of LaTeX
to Markdown, and used a few more to convert the sMarkdown to
MathJaX-convertible Markdown.

Example
-------

As an example, the following LaTeX code:

::

    \section{Example Section}
    \begin{thm}[Euclid]
        There are infinitely many primes.
    \end{thm}

    \begin{proof}
        Suppose that $p_1 < p_2 < \dots < p_n$ are all of the primes. 
        Let $P = 1 + \prod_{i=1}^n p_i$ and let $p$ be a prime dividing $P$.

        Then $p$ can not be any of $p_i$, for otherwise $p$ would divide the 
        difference $P - \left(\prod_{i=1}^n p_i \right) - 1$, which is impossible. 
        So this prime $p$ is still another prime, and $p_1, p_2, \dots p_n$ 
        cannot be all of the primes.
    \end{proof}

is converted into the following Markdown:

::

    ###  Example Section
    #### Theorem 1 (Euclid)

    > There are infinitely many primes.

    #### Proof

    Suppose that $p_1 < p_2 < \dots < p_n$ are all of the primes. 
    Let $P = 1 + \prod_{i=1}^n p_i$ and let $p$ be a prime dividing $P$.

    Then $p$ can not be any of $p_i$, for otherwise $p$ would divide the difference 
    $P - \left(\prod_{i=1}^n p_i \right) - 1$, which is impossible. So this prime 
    $p$ is still another prime, and $p_1, p_2, \dots p_n$ cannot be all of the primes.

Supported LaTeX/AMSTeX Environments
-----------------------------------

-  ``emph``, ``textbf``, ``texttt``
-  ``thm``
-  ``prop``
-  ``lem``
-  ``exer``
-  ``proof``
-  ``chapter``
-  ``section``
-  ``subsection``
-  ``itemize``
-  ``enumerate``

along with everything supported by MathJax - list available
`online <http://www.mathjax.org/docs/2.0/tex.html#supported-latex-commands>`_.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ajtulloch/LaTeX2Markdown",
    "name": "latex2markdown",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Andrew Tulloch",
    "author_email": "andrew@tullo.ch",
    "download_url": "https://files.pythonhosted.org/packages/33/f9/2f450ece27153993f8dd9d543a3b7e0948ec3026ff53dbf65ac3e234a446/latex2markdown-0.2.1.tar.gz",
    "platform": "UNKNOWN",
    "description": "LaTeX2Markdown\n==============\n\nAn `AMS-LaTeX <http://en.wikipedia.org/wiki/AMS-LaTeX>`_ compatible\nconverter from (a subset of) `LaTeX <http://www.latex-project.org/>`_ to\n`MathJaX <http://www.mathjax.org/>`_ compatible\n`Markdown <http://daringfireball.net/projects/markdown/>`_.\n\nAnyone who writes LaTeX documents using the AMS-LaTeX packages\n(``amsmath``, ``amsthm``, ``amssymb``) and wants to convert these\ndocuments to Markdown format to use with MathJaX. These Markdown files\ncan then be easily added to any web platform - Jekyll blogs, Wordpress,\nbasic HTML sites, etc.\n\nIn short, if you seek to use MathJaX to view your LaTeX documents\nonline, then you might be interested in this.\n\nDemonstration\n-------------\n\nCheck out\n`tullo.ch/projects/LaTeX2Markdown <http://tullo.ch/projects/LaTeX2Markdown>`_\nfor a live demonstration of the converter.\n\nGetting Started\n---------------\n\nInstallation\n~~~~~~~~~~~~\n\nThe project is available on PyPI, so getting it is as simple as using\n\n::\n\n    pip install latex2markdown\n\nor\n\n::\n\n    easy_install latex2markdown\n\nUsage\n~~~~~\n\nThe utility can be called from the command line, or from within a Python\nscript.\n\nFor the command line, the syntax to convert a LaTeX file to a Markdown\nfile is as follows:\n\n::\n\n    python -m latex2markdown path/to/latex/file path/to/output/markdown/file\n\nFor example, to compile a LaTeX file ``sample.tex`` into a Markdown file\n``sample.md``, call\n\n::\n\n    python -m latex2markdown sample.tex sample.md\n\nTo use it within a Python script (to extend it, modify output, etc.),\nyou can use it as follows:\n\n::\n\n    import latex2markdown\n    with open(\"latex_file.tex\", \"r\") as f:\n        latex_string = f.read()\n\n    l2m = latex2markdown.LaTeX2Markdown(latex_string)\n\n    markdown_string = l2m.to_markdown()\n\n    with open(\"markdown_file.md\", \"w\") as f:\n        f.write(markdown_string)\n\nFinally, add the following snippet to your HTML when loading this\ndocument.\n\n::\n\n    <script type=\"text/x-mathjax-config\">\n        MathJax.Hub.Config({\n            extensions: [\"tex2jax.js\", \"AMSmath.js\"],\n            jax: [\"input/TeX\", \"output/HTML-CSS\"],\n            tex2jax: {\n                inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n                displayMath: [ ['$$','$$'], [\"\\[\",\"\\]\"] ],\n                processEscapes: true\n            },\n        });\n    </script>\n    <script type=\"text/javascript\" src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\">\n    </script>\n\nFor a working example, have a look at the source of the\n`tullo.ch <http://tullo.ch>`_ homepage\n`here <https://github.com/ajtulloch/ajtulloch.github.com>`_.\n\nWhy not use Pandoc?\n-------------------\n\n`Pandoc <http://johnmacfarlane.net/pandoc/%20##%20Who%20should%20use%20this?>`_\nis an excellent document converter for less complex LaTeX documents.\nIndeed, I've used it to convert this README document to a reST version\nfor use on PyPI.\n\nUnfortunately, it is not designed to deal with documents that use the\nAMSTeX extensions - which include the theorem, lemma, proof, and\nexercise environments that are heavily used for typesetting papers,\nlecture notes, and other documents.\n\nAs neither Pandoc nor MathJaX can deal with these documents, I hacked\ntogether a set of regular expressions that can convert a subset of LaTeX\nto Markdown, and used a few more to convert the sMarkdown to\nMathJaX-convertible Markdown.\n\nExample\n-------\n\nAs an example, the following LaTeX code:\n\n::\n\n    \\section{Example Section}\n    \\begin{thm}[Euclid]\n        There are infinitely many primes.\n    \\end{thm}\n\n    \\begin{proof}\n        Suppose that $p_1 < p_2 < \\dots < p_n$ are all of the primes. \n        Let $P = 1 + \\prod_{i=1}^n p_i$ and let $p$ be a prime dividing $P$.\n\n        Then $p$ can not be any of $p_i$, for otherwise $p$ would divide the \n        difference $P - \\left(\\prod_{i=1}^n p_i \\right) - 1$, which is impossible. \n        So this prime $p$ is still another prime, and $p_1, p_2, \\dots p_n$ \n        cannot be all of the primes.\n    \\end{proof}\n\nis converted into the following Markdown:\n\n::\n\n    ###  Example Section\n    #### Theorem 1 (Euclid)\n\n    > There are infinitely many primes.\n\n    #### Proof\n\n    Suppose that $p_1 < p_2 < \\dots < p_n$ are all of the primes. \n    Let $P = 1 + \\prod_{i=1}^n p_i$ and let $p$ be a prime dividing $P$.\n\n    Then $p$ can not be any of $p_i$, for otherwise $p$ would divide the difference \n    $P - \\left(\\prod_{i=1}^n p_i \\right) - 1$, which is impossible. So this prime \n    $p$ is still another prime, and $p_1, p_2, \\dots p_n$ cannot be all of the primes.\n\nSupported LaTeX/AMSTeX Environments\n-----------------------------------\n\n-  ``emph``, ``textbf``, ``texttt``\n-  ``thm``\n-  ``prop``\n-  ``lem``\n-  ``exer``\n-  ``proof``\n-  ``chapter``\n-  ``section``\n-  ``subsection``\n-  ``itemize``\n-  ``enumerate``\n\nalong with everything supported by MathJax - list available\n`online <http://www.mathjax.org/docs/2.0/tex.html#supported-latex-commands>`_.",
    "bugtrack_url": null,
    "license": "UNKNOWN",
    "summary": "An AMS-LaTeX compatible converter that maps a subset of LaTeX to Markdown/MathJaX.",
    "version": "0.2.1",
    "project_urls": {
        "Download": "UNKNOWN",
        "Homepage": "https://github.com/ajtulloch/LaTeX2Markdown"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33f92f450ece27153993f8dd9d543a3b7e0948ec3026ff53dbf65ac3e234a446",
                "md5": "cbc35460a6ec1f5c0ba1b3b5820a637b",
                "sha256": "beac7a10cc559f723f7fa4cadf501e18ebc8f4c40ca94fde94fff1591961b81e"
            },
            "downloads": -1,
            "filename": "latex2markdown-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "cbc35460a6ec1f5c0ba1b3b5820a637b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 161687,
            "upload_time": "2012-04-03T05:15:03",
            "upload_time_iso_8601": "2012-04-03T05:15:03.109404Z",
            "url": "https://files.pythonhosted.org/packages/33/f9/2f450ece27153993f8dd9d543a3b7e0948ec3026ff53dbf65ac3e234a446/latex2markdown-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2012-04-03 05:15:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ajtulloch",
    "github_project": "LaTeX2Markdown",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "latex2markdown"
}
        
Elapsed time: 0.29038s