Giter Club home page Giter Club logo

pandoc-amsthm's Introduction

Define amsthm environment in YAML front matter and use it with a native pandoc div in the main document. Using the templates and filter provided, HTML and LaTeX output using amsthm can be realized.

Demo are available at https://ickc.github.io/pandoc-amsthm/.

Usage

pandoc-amsthm defines a new syntax above pandoc markdown. It is then processed through the use of provided pandoc templates and filter.

So far, only LaTeX and HTML related output are supported.

Syntax

YAML Front Matter

For example, as in template/include/default.yml,

---
amsthm:
  plain:
  - Theorem
  plain-unnumbered:
  - Lemma
  - Proposition
  - Corollary
  definition:
  - Definition
  - Conjecture
  - Example
  - Postulate
  - Problem
  remark:
  - Case
  remark-unnumbered:
  - Remark
  - Note
  proof:
  - proof
  parentcounter:
  - chapter
...

Notes:

  • proof: & - [proof] is mandatory [1]

  • parentcounter is optional, common choices are chapter, section. Depending on the document class, it can be part, chapter, section, subsection, subsubsection, paragraph, subparagraph. It only affects LaTeX output.

  • plain, definition, and remark are the theorem styles provided by amsthm.

  • the suffix -unnumbered means unnumbered, otherwise numbered. (i.e. you can also use definition-unnumbered)

  • First letter of the amsthm environment should be capitalized (they will be printed as is in HTML), except for proof, which has to be in lower case (to match the pre-defined amsthm proof environment).

  • The above YAML is equivalent to

    ---
    amsthm:
      plain:    [Theorem]
      plain-unnumbered: [Lemma, Proposition, Corollary]
      definition:   [Definition,Conjecture,Example,Postulate,Problem]
      definition-unnumbered:    []
      remark:   [Case]
      remark-unnumbered:    [Remark,Note]
      proof:    [proof]
      parentcounter:    [chapter]
    ...
    

[1] because amsthm predefines it.

Amsthm environment

Each amsthm environment should be defined with a native pandoc div, with a class named as the environment defined through the YAML front matter. Like this:

<div class="proof">
A Proof.
</div>

Templates and Filter

The provided templates and filter are needed for pandoc to process the above defined syntax properly.

To use the given filter in bin/, add --filter=<pathto>pandoc-amsthm.py to your pandoc command. If you put put it in your PATH, then you only need --filter=pandoc-amsthm.py. [2]

[2] Strictly speaking, you only need to include the filter for LaTeX output. HTML related outputs only requires the templates.

There are 2 ways to use the templates. If you do not need to customize the templates, 3 complete templates are provided in template/ folder. Use the template according to the output format by adding this in your pandoc argument: --template=<pathto>pandoc-amsthm.<ext>.

If you need to customize your template (or need other HTML related output not provided here, e.g. ePub.), 2 templates named are given in template/include/pandoc-amsthm.*. They are fragments only. You need to insert the given fragment into the head or preamble for HTML and LaTeX respectively.

Sensible Defaults

In issue #3, there is a request on using the default without repeating the YAML front matter every time. It can be done. Using the files in template/include/default.*:

pandoc -H <PATHTO>default.html <INPUT>.md -o <OUTPUT>.html
cat <PATHTO>default.yml <INPUT>.md | pandoc -H <PATHTO>default.latex --filter=<PATHTO>pandoc-amsthm.py -o <OUTPUT>.pdf

template/include/makefile shows how the defaults are produced.

Caveats

CSS Counter

In the CSS defined through the HTML templates,

  • a .dump is used, basically because I have 4 for loops together and I have no way to guarantee it doesn’t end with a comma, since any of the array can be empty.
  • The CSS counter is reset by html. If you use other CSS, and have other CSS counter set by html, you need to change that (body is another possible choice). If there’s two separately defined CSS counter reset based on the same html or body then there would be trouble (and to resolve the conflict, they should be combined together).

Pandoc-Citeproc

Currently if pandoc-citeproc is used before this filter, there’s an error. So this filter should be used first. Like this: --filter=pandoc-amsthm.py --filter=pandoc-citeproc.

Credit

The Python script used is modified from chdemko/pandoc-latex-environment, which is under CeCILL-B license.

pandoc-amsthm's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.