latexpp


Namelatexpp JSON
Version 0.2.0a1 PyPI version JSON
download
home_page
SummaryLatex preprocessor — apply macro definitions, remove comments, and more
upload_time2023-04-26 18:38:28
maintainer
docs_urlNone
authorPhilippe Faist
requires_python>=3.7,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            latexpp
=======

Latex preprocessor — apply macro definitions, remove comments, and more

*Disclaimer: latexpp is still at an experimental development stage.*

.. image:: https://img.shields.io/github/license/phfaist/latexpp.svg?style=flat
   :target: https://github.com/phfaist/latexpp/blob/master/LICENSE.txt
   

Installation
------------

You can install `latexpp` using `pip` directly from `latexpp`'s github repo:

.. code-block:: sh

    > pip install git+https://github.com/phfaist/latexpp.git

How it works
------------

The latex preprocessor ``latexpp`` reads your main latex document and copies it
to an output directory while applying a series of "fixes" that you can
configure.  For instance, you can remove comments, you can include files that
you input with ``\input`` macros, or you can replace custom macros by their
LaTeX expansion.

You run ``latexpp`` in a folder with a ``lppconfig.yml`` file that specifies the
necessary information such as the main LaTeX document, the output directory, and
which fixes to apply.

Sample ``lppconfig.yml``:

.. code-block:: yaml

  # latexpp config for MyDocument.tex
  #
  # This is YAML syntax -- google "YAML tutorial" to get a quick intro.  Be
  # careful with spaces since indentation is important.

  # the master LaTeX document -- this file will not be modified, all output will
  # be produced in the output_dir
  fname: 'MyDocument.tex'

  # output file(s) will be created in this directory, originals will not be
  # modified
  output_dir: 'latexpp_output'
  
  # main document file name in the output directory
  output_fname: 'paper.tex'

  # specify list of fixes to apply, in the given order
  fixes:

    # replace \input{...} directives by the contents of the included file
    - 'latexpp.fixes.input.EvalInput'
  
    # remove all comments
    - 'latexpp.fixes.comments.RemoveComments'

    # copy any style files (.sty) that are used in the document and that
    # are present in the current directory to the output directory
    - 'latexpp.fixes.usepackage.CopyLocalPkgs'
  
    # copy figure files to the output directory and rename them fig-1.xxx,
    # fig-2.xxx, etc.
    - 'latexpp.fixes.figures.CopyAndRenameFigs'

    # Replace \bibliography{...} by \input{xxx.bbl} and copy the bbl file to the
    # output directory.  Make sure you run (pdf)latex on the main docuemnt
    # before running latexpp
    - 'latexpp.fixes.bib.CopyAndInputBbl'
  
    # Expand some macros. Latexpp doesn't parse \newcommand's, so you need to
    # specify here the LaTeX code that the macro should be expanded to. If the
    # macro has arguments, specify the nature of the arguments here in the
    # 'argspec:' key (a '*' is an optional * character, a '[' one optional
    # square-bracket-delimited argument, and a '{' is a mandatory argument). The
    # argument values are available via the placeholders %(1)s, %(2)s, etc. Make
    # sure to use single quotes for strings that contain \ backslashes.
    - name: 'latexpp.fixes.macro_subst.Subst'
      config:
        macros:
          # \tr         -->  \operatorname{tr}
          tr: '\operatorname{tr}'
          # \ket{\psi}  -->  \lvert{\psi}\rangle
          ket:
            argspec: '{'
            repl: '\lvert{%(1)s}\rangle'
          # \braket{\psi}{\phi}  -->  \langle{\psi}\vert{\phi}\rangle
          braket:
            argspec: '{{'
            repl: '\langle{%(1)s}\vert{%(2)s}\rangle'

The config file follows standard YAML syntax (if you're in doubt, google a YAML
tutorial).

Documentation is available at `latexpp.readthedocs.io
<https://latexpp.readthedocs.io/>`_. You can also explore the ``latexpp/fixes/``
directory for the list of possible fixes.  The documentation is still a little
sparse at the moment (I wrote this preprocessor in the
matter of a few days, and I won't have tons of time to devote to it). But the
python source is fairly short and should be relatively decipherable.

Each fix is specified by a qualified python class name.  For instance,
``latexpp.fixes.comments.RemoveComments`` invokes class ``RemoveComments`` from
the python module ``latexpp.fixes.comments``.  You can specify custom arguments
to the class constructor by using the syntax with the 'name:' and 'config:' keys
as shown above.  The keys in each 'config:' section are directly passed on to
the class constructor as corresponding keyword arguments.

The fixes in the ``latexpp/fixes/pkg/`` directory are those fixes that are
supposed to apply all definitions of the corresponding package in order to
remove a dependency on that package.

It's also straightforward to write your own fix classes to do more complicated
stuff.  Create a python package (a new folder ``mypackage`` with an empty
``__init__.py`` file) and create a python module (e.g. ``myfixmodule.py``) in
that package that defines your fix class (e.g. ``MyFix``).  You can get
inspiration from one of the simple examples in the ``latexpp/fixes/`` folder.
Set up your ``$PYTHONPATH`` so that your python package is exposed to python.
Then simply specify the pacakge/module your fix is located in in the YAML file,
e.g., ``mypackage.myfixmodule.MyFix`` instead of
``latexpp.fixes.xxxxx.YYYY``.

How it actually works
---------------------

The ``latexpp`` preprocessor relies on `pylatexenc 2.0
<https://github.com/phfaist/pylatexenc>`_ to parse the latex document into an
internal node structure.  For instance, the chunk of latex code::
  
  Hello, \textit{world}! % show a greeting

will be parsed into a list of four nodes, a ‘normal characters node’ ``"Hello,
"``, a ‘macro node’ ``\textit`` with argument a ‘group node’ ``{world}`` which
itself contains a ‘normal characters node’ ``world``, a ‘normal characters node’
``"! "``, and a ‘latex comment node’ ``% show a greeting``.  The structure is
recursive, with e.g. macro arguments and environment contents themselves
represented as nodes which can contain further macros and environments.  See
`pylatexenc.latexwalker
<https://pylatexenc.readthedocs.io/en/latest/latexwalker/>`_ for more
information.  The `pylatexenc` library has a list of some known macros and
environments, and knows how to parse their arguments.  Some fixes in `latexpp`
add their own macro and environment definitions.

Once the latex document is parsed into the node structure, the document is
processed by the given list of fixes. Each fix is called in turn. Each fix
traverses the document node structure and applies any relevant changes.


License
-------

\ (C) 2019 Philippe Faist, philippe dot faist <at@at> bluewin dot ch

MIT Licence, see License.txt


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "latexpp",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Philippe Faist",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/78/68/3086b6cac1c3fcbc8eecef35a26f948e0aca46e3b0048845e450c2ad1351/latexpp-0.2.0a1.tar.gz",
    "platform": null,
    "description": "latexpp\n=======\n\nLatex preprocessor \u2014 apply macro definitions, remove comments, and more\n\n*Disclaimer: latexpp is still at an experimental development stage.*\n\n.. image:: https://img.shields.io/github/license/phfaist/latexpp.svg?style=flat\n   :target: https://github.com/phfaist/latexpp/blob/master/LICENSE.txt\n   \n\nInstallation\n------------\n\nYou can install `latexpp` using `pip` directly from `latexpp`'s github repo:\n\n.. code-block:: sh\n\n    > pip install git+https://github.com/phfaist/latexpp.git\n\nHow it works\n------------\n\nThe latex preprocessor ``latexpp`` reads your main latex document and copies it\nto an output directory while applying a series of \"fixes\" that you can\nconfigure.  For instance, you can remove comments, you can include files that\nyou input with ``\\input`` macros, or you can replace custom macros by their\nLaTeX expansion.\n\nYou run ``latexpp`` in a folder with a ``lppconfig.yml`` file that specifies the\nnecessary information such as the main LaTeX document, the output directory, and\nwhich fixes to apply.\n\nSample ``lppconfig.yml``:\n\n.. code-block:: yaml\n\n  # latexpp config for MyDocument.tex\n  #\n  # This is YAML syntax -- google \"YAML tutorial\" to get a quick intro.  Be\n  # careful with spaces since indentation is important.\n\n  # the master LaTeX document -- this file will not be modified, all output will\n  # be produced in the output_dir\n  fname: 'MyDocument.tex'\n\n  # output file(s) will be created in this directory, originals will not be\n  # modified\n  output_dir: 'latexpp_output'\n  \n  # main document file name in the output directory\n  output_fname: 'paper.tex'\n\n  # specify list of fixes to apply, in the given order\n  fixes:\n\n    # replace \\input{...} directives by the contents of the included file\n    - 'latexpp.fixes.input.EvalInput'\n  \n    # remove all comments\n    - 'latexpp.fixes.comments.RemoveComments'\n\n    # copy any style files (.sty) that are used in the document and that\n    # are present in the current directory to the output directory\n    - 'latexpp.fixes.usepackage.CopyLocalPkgs'\n  \n    # copy figure files to the output directory and rename them fig-1.xxx,\n    # fig-2.xxx, etc.\n    - 'latexpp.fixes.figures.CopyAndRenameFigs'\n\n    # Replace \\bibliography{...} by \\input{xxx.bbl} and copy the bbl file to the\n    # output directory.  Make sure you run (pdf)latex on the main docuemnt\n    # before running latexpp\n    - 'latexpp.fixes.bib.CopyAndInputBbl'\n  \n    # Expand some macros. Latexpp doesn't parse \\newcommand's, so you need to\n    # specify here the LaTeX code that the macro should be expanded to. If the\n    # macro has arguments, specify the nature of the arguments here in the\n    # 'argspec:' key (a '*' is an optional * character, a '[' one optional\n    # square-bracket-delimited argument, and a '{' is a mandatory argument). The\n    # argument values are available via the placeholders %(1)s, %(2)s, etc. Make\n    # sure to use single quotes for strings that contain \\ backslashes.\n    - name: 'latexpp.fixes.macro_subst.Subst'\n      config:\n        macros:\n          # \\tr         -->  \\operatorname{tr}\n          tr: '\\operatorname{tr}'\n          # \\ket{\\psi}  -->  \\lvert{\\psi}\\rangle\n          ket:\n            argspec: '{'\n            repl: '\\lvert{%(1)s}\\rangle'\n          # \\braket{\\psi}{\\phi}  -->  \\langle{\\psi}\\vert{\\phi}\\rangle\n          braket:\n            argspec: '{{'\n            repl: '\\langle{%(1)s}\\vert{%(2)s}\\rangle'\n\nThe config file follows standard YAML syntax (if you're in doubt, google a YAML\ntutorial).\n\nDocumentation is available at `latexpp.readthedocs.io\n<https://latexpp.readthedocs.io/>`_. You can also explore the ``latexpp/fixes/``\ndirectory for the list of possible fixes.  The documentation is still a little\nsparse at the moment (I wrote this preprocessor in the\nmatter of a few days, and I won't have tons of time to devote to it). But the\npython source is fairly short and should be relatively decipherable.\n\nEach fix is specified by a qualified python class name.  For instance,\n``latexpp.fixes.comments.RemoveComments`` invokes class ``RemoveComments`` from\nthe python module ``latexpp.fixes.comments``.  You can specify custom arguments\nto the class constructor by using the syntax with the 'name:' and 'config:' keys\nas shown above.  The keys in each 'config:' section are directly passed on to\nthe class constructor as corresponding keyword arguments.\n\nThe fixes in the ``latexpp/fixes/pkg/`` directory are those fixes that are\nsupposed to apply all definitions of the corresponding package in order to\nremove a dependency on that package.\n\nIt's also straightforward to write your own fix classes to do more complicated\nstuff.  Create a python package (a new folder ``mypackage`` with an empty\n``__init__.py`` file) and create a python module (e.g. ``myfixmodule.py``) in\nthat package that defines your fix class (e.g. ``MyFix``).  You can get\ninspiration from one of the simple examples in the ``latexpp/fixes/`` folder.\nSet up your ``$PYTHONPATH`` so that your python package is exposed to python.\nThen simply specify the pacakge/module your fix is located in in the YAML file,\ne.g., ``mypackage.myfixmodule.MyFix`` instead of\n``latexpp.fixes.xxxxx.YYYY``.\n\nHow it actually works\n---------------------\n\nThe ``latexpp`` preprocessor relies on `pylatexenc 2.0\n<https://github.com/phfaist/pylatexenc>`_ to parse the latex document into an\ninternal node structure.  For instance, the chunk of latex code::\n  \n  Hello, \\textit{world}! % show a greeting\n\nwill be parsed into a list of four nodes, a \u2018normal characters node\u2019 ``\"Hello,\n\"``, a \u2018macro node\u2019 ``\\textit`` with argument a \u2018group node\u2019 ``{world}`` which\nitself contains a \u2018normal characters node\u2019 ``world``, a \u2018normal characters node\u2019\n``\"! \"``, and a \u2018latex comment node\u2019 ``% show a greeting``.  The structure is\nrecursive, with e.g. macro arguments and environment contents themselves\nrepresented as nodes which can contain further macros and environments.  See\n`pylatexenc.latexwalker\n<https://pylatexenc.readthedocs.io/en/latest/latexwalker/>`_ for more\ninformation.  The `pylatexenc` library has a list of some known macros and\nenvironments, and knows how to parse their arguments.  Some fixes in `latexpp`\nadd their own macro and environment definitions.\n\nOnce the latex document is parsed into the node structure, the document is\nprocessed by the given list of fixes. Each fix is called in turn. Each fix\ntraverses the document node structure and applies any relevant changes.\n\n\nLicense\n-------\n\n\\ (C) 2019 Philippe Faist, philippe dot faist <at@at> bluewin dot ch\n\nMIT Licence, see License.txt\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Latex preprocessor \u2014 apply macro definitions, remove comments, and more",
    "version": "0.2.0a1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61b16c8b8153b5e28db63aadad57613bc89d1ab982818b7acb4124d4b2a79e3e",
                "md5": "d70639f7482555c62ec412033c19340f",
                "sha256": "c227d56451821f6d209983d9585042e2dfd69dd45ca5b63ba685e770c1ebca75"
            },
            "downloads": -1,
            "filename": "latexpp-0.2.0a1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d70639f7482555c62ec412033c19340f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 92295,
            "upload_time": "2023-04-26T18:38:27",
            "upload_time_iso_8601": "2023-04-26T18:38:27.162564Z",
            "url": "https://files.pythonhosted.org/packages/61/b1/6c8b8153b5e28db63aadad57613bc89d1ab982818b7acb4124d4b2a79e3e/latexpp-0.2.0a1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "78683086b6cac1c3fcbc8eecef35a26f948e0aca46e3b0048845e450c2ad1351",
                "md5": "d95eeec4a136e3f95d88b392d00225ea",
                "sha256": "18a7fc86001942a0247410492ad82dc764e4463d871e0643465e2dd93cb3eac1"
            },
            "downloads": -1,
            "filename": "latexpp-0.2.0a1.tar.gz",
            "has_sig": false,
            "md5_digest": "d95eeec4a136e3f95d88b392d00225ea",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 79777,
            "upload_time": "2023-04-26T18:38:28",
            "upload_time_iso_8601": "2023-04-26T18:38:28.734839Z",
            "url": "https://files.pythonhosted.org/packages/78/68/3086b6cac1c3fcbc8eecef35a26f948e0aca46e3b0048845e450c2ad1351/latexpp-0.2.0a1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-26 18:38:28",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "latexpp"
}
        
Elapsed time: 0.07253s