Giter VIP home page Giter VIP logo

pandoc-tablenos's Introduction

NEW: Clickable references in docx; Table numbers by section in LaTeX/pdf and html.

pandoc-tablenos 0.16

pandoc-tablenos is a pandoc filter for numbering tables and table references in processed markdown documents. A cross-referencing syntax is added to markdown for this purpose.

Demonstration: Processing demo3.md with pandoc --filter pandoc-tablenos gives numbered tables and references in pdf, tex, html, epub, docx and other formats.

This version of pandoc-tablenos was tested using pandoc 1.15.2 - 1.19.1. It works under linux, Mac OS X and Windows. Older versions and other platforms can be supported on request. I am pleased to receive bug reports and feature requests on the project's Issues tracker.

If you find pandoc-tablenos useful, then please encourage further development by giving it a star on GitHub.

See also: pandoc-fignos, pandoc-eqnos

Contents

  1. Usage
  2. Markdown Syntax
  3. Customization
  4. Details
  5. Installation
  6. Getting Help

Usage

To apply the filter during document processing, use the following option with pandoc:

--filter pandoc-tablenos

Note that any use of --filter pandoc-citeproc or --bibliography=FILE should come after the pandoc-tablenos filter call.

Markdown Syntax

The markdown syntax extension used by pandoc-tablenos was worked out in pandoc Issue #813 -- see this post by @scaramouche1.

To mark a table for numbering, add the label tbl:id to the attributes of its caption:

A B
- -
0 1

Table: Caption. {#tbl:id}

The prefix #tbl: is required. id should be replaced with a unique identifier composed of letters, numbers, dashes, slashes and underscores. If id is omitted then the figure will be numbered but unreferenceable.

To reference the table, use

@tbl:id

or

{@tbl:id}

Curly braces around a reference are stripped from the output.

Demonstration: Processing demo.md with pandoc --filter pandoc-tablenos gives numbered tables and references in pdf, tex, html, epub, docx and other formats.

Clever References

Writing markdown like

See table @tbl:id.

seems a bit redundant. Pandoc-tablenos supports "clever referencing" via single-character modifiers in front of a reference. You can write

 See +@tbl:id.

to have the reference name (i.e., "table") automatically generated. The above form is used mid-sentence. At the beginning of a sentence, use

 *@tbl:id

instead. If clever referencing is enabled by default (see Customization, below), you can disable it for a given reference using1

!@tbl:id

Demonstration: Processing demo2.md with pandoc --filter pandoc-tablenos gives numbered tables and references in pdf, tex, html, epub, docx and other formats.

Note: If you use *tbl:id and emphasis (e.g., *italics*) in the same sentence, then you must backslash escape the * in the clever reference; e.g., \*tbl:id.

Tagged Tables

You may optionally override the table number by placing a tag in a table's attributes block as follows:

A B
- -
0 1

Table: Caption. {#tbl:id tag="B.1"}

The tag may be arbitrary text, or an inline equation such as $\text{B.1}'$. Mixtures of the two are not currently supported.

Customization

Pandoc-tablenos may be customized by setting variables in the metadata block or on the command line (using -M KEY=VAL). The following variables are supported:

  • tablenos-caption-name - Sets the name at the beginning of a caption (e.g., change it from "Table to "Tab.");

  • tablenos-cleveref or just cleveref - Set to On to assume "+" clever references by default;

  • tablenos-plus-name - Sets the name of a "+" reference (e.g., change it from "table" to "tab."); and

  • tablenos-star-name - Sets the name of a "*" reference (e.g., change it from "Table" to "Tab.").

Demonstration: Processing demo3.md with pandoc --filter pandoc-tablenos gives numbered tables and references in pdf, tex, html, epub, docx and other formats.

Table Numbers by Section

The --number-sections option enables section numbers in pandoc. Table numbers by section (e.g., "Tab. 2.1") can be obtained as follows:

  1. html: Add xnos-section-numbers: On to your YAML metadata or use the -M xnos-section-numbers=On option with pandoc. This variable is ignored for other output formats.

  2. LaTeX/pdf: Add header-includes: \numberwithin{table}{section} to your YAML metadata. If you need multiple header includes, then add something like this:

    header-includes:
      - \numberwithin{figure}{section}
      - \numberwithin{equation}{section}
      - \numberwithin{table}{section}
    

    Alternatively, write your header includes into FILE, and use the --include-in-header=FILE option with pandoc.

    If you set either --top-level-division=part or --top-level-division=chapter then these header includes can be dropped.

    LaTeX header-includes are ignored for html output.

Latex/PDF Specializations

To make the table caption label bold, add \usepackage[labelfont=bf]{caption} to the header-includes field of your document's YAML metadata. See the LaTeX caption package documentation for additional features.

Details

TeX/pdf:

  • The \label and \ref macros are used for table labels and references;
  • \figurename is set for the caption name;
  • Tags are supported by temporarily redefining \thetable around a table; and
  • The clever referencing macros \cref and \Cref are used if they are available (i.e. included in your LaTeX template via \usepackage{cleveref}), otherwise they are faked. Set the meta variable xnos-cleveref-fake to Off to disable cleveref faking.

Other formats:

  • Links to figures use html's and docx's native capabilities; and

  • The numbers, caption name, and (clever) references are hard-coded into the output.

Installation

Pandoc-tablenos requires python, a programming language that comes pre-installed on linux and Mac OS X, and which is easily installed on Windows. Either python 2.7 or 3.x will do.

Standard installation

Install pandoc-tablenos as root using the shell command

pip install pandoc-tablenos 

To upgrade to the most recent release, use

pip install --upgrade pandoc-tablenos 

Pip is a program that downloads and installs modules from the Python Package Index, PyPI. It should come installed with your python distribution.

Troubleshooting

If you are prompted to upgrade pip, then do so. Installation errors may occur with older versions. The command you need to execute (as root) is

python -m pip install --upgrade pip

You may test the installation as a regular user using the shell command

which pandoc-tablenos

This will tell you where pandoc-tablenos is installed. If it is not found, then please submit a report to our Issues tracker.

Installing on linux

If you are running linux, pip may be packaged separately from python. On Debian-based systems (including Ubuntu), you can install pip as root using

apt-get update
apt-get install python-pip

During the install you may be asked to run

easy_install -U setuptools

owing to the ancient version of setuptools that Debian provides. The command should be executed as root. You may now follow the standard installation procedure given above.

Installing on Mac OS X

To install as root on Mac OS X, you will need to use the sudo command. For example:

sudo pip install pandoc-tablenos

Troubleshooting with which should be done as a regular user (i.e., without using sudo).

Installing on Windows

It is easy to install python on Windows. First, download the latest release. Run the installer and complete the following steps:

  1. Install Python pane: Check "Add Python 3.5 to path" then click "Customize installation".

  2. Optional Features pane: Click "Next".

  3. Advanced Options pane: Optionally check "Install for all users" and customize the install location, then click "Install".

Once python is installed, start the "Command Prompt" program. Depending on where you installed python, you may need elevate your privileges by right-clicking the "Command Prompt" program and selecting "Run as administrator". You may now follow the standard installation procedure given above. Be sure to close the Command Prompt program when you have finished.

Getting Help

If you have any difficulties with pandoc-tablenos, or would like to see a new feature, please submit a report to our Issues tracker.


Footnotes

1: The disabling modifier "!" is used instead of "-" because pandoc unnecessarily drops minus signs in front of references.

pandoc-tablenos's People

Contributors

tomduck avatar

Watchers

Rohit Yadav 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.