Git Product home page Git Product logo

pandocacademic's Introduction

Pandoc Academic Plugin for Sublime Text 2/3

A Sublime Text 2/3 plugin to handle Pandoc. The plugin proposes:

  • a syntax highlighting tool associated with two dark color themes,
  • different snippets to quickly add Pandoc functions
  • a conversion tool to transform a Pandoc file to HTML, DocX, PDF and Beamer documents.

Based on the Pandoc Render plugin.

Version

Plugin version: v1.1 -- Automatically launch the file-associated program after the compilation.

Plugin version: v1.2 -- Add the grid table module and the LaTeX class option.

Plugin version: v1.3 -- Convert the script to run on Python 3 / Sublime Text 3

Installation

The easiest way to install the package is to use the package control manager. Go to Preferences > Package Control > Install Package and search for "Pandoc Academic".

You can also install the plugin manually. Download the latest version from Github and copy the folder into your Sublime Text 2 Packages folder. (for instance in Linux: ~/.config/sublime-text-2/Packages).

$ git clone [email protected]:larlequin/PandocAcademic.git

Dependencies

You need to have a working installation of Pandoc, version 1.9.4.2 or higher.

Available Commands

Syntax and color scheme

You can select the syntax for a markdown file (Pandoc) in the Menu: View > Syntax > Pandoc. This syntax should be selected to make the conversion menu available.

The compatible color schemes are available in the Menu: Preferences > Color Scheme > Pandoc Academic > ColorScheme.

Conversion

Conversions are available in the Menu: Tools > Pandoc Academic > Pandoc Convert (only if Pandoc is defined as syntax). You can convert a Pandoc file to:

  • HTML
  • DocX
  • PDF (via LaTeX, see Pandoc documentation)
  • Beamer (via LaTeX, see Pandoc documentation)

You can also use key shortcuts to launch the conversions:

  • HTML > CTL+ALT+h
  • DocX > CTL+ALT+d
  • Beamer > CTL+ALT+b
  • PDF > CTL+SHIFT+ALT+p

Snippets

Generic snippets:

  • co + tabulation = snippet to add a comment (HTML format)
  • bo + tabulation = snippet to add bold text in Pandoc/Markdown (**)
  • it + tabulation = snippet to add italic text in Pandoc/Markdown (*)
  • link + tabulation= snippet to add a web link in Pandoc/Markdown

Figures and Tables:

  • img + tabulation = snippet to add a picture in Pandoc
  • tab + tabulation = snippet to add a table from a file and its title (as for an article)

Citation/bibliography snippets:

  • ci + tabulation = snippet to add a citation in brackets [text? @citationkey]
  • bib + tabulation = add the [[BIB]] option to the current file

Mathematic snippets:

  • mat + tabulation = snippet to add mathematics based on LaTeX style
  • pow + tabulation = snippet to add the eta squared symbol

Other snippets:

  • not + tabulation = add a footnote
  • toc + tabulation = add the [[TOC]] option to the current file
  • temp + tabulation = add the [[DOCSYTLE=name]] option to the current file
  • class + tabulation= add the [[CLASS=name]] option to the current file
  • head + tabulation = add the [[HEADER]] option to the current file
  • rend + tabulation = add the [[NORENDER]] option to the current

Pandoc Options

The following hints can be added in your document to flip on additional features in Pandoc:

  • <!-- [[TOC]] -->: Add a Table of Contents to the top of your output document.
  • <!-- [[NUM]] -->: Turn on numbering of sections.
  • <!-- [[BIB]] -->: Add the bibliography option to handle citation and reference (@citationkey). The bibliography file should have the same name as the Pandoc file.
  • <!-- [[BIBSTYLE=name]] -->: Specify a csl bibliography style.
  • <!-- [[DOCSTYLE=name]] -->: Specify a template for the convertion to HTML or DOCX or theme in Beamer.
  • <!-- [[CLASS=name]] -->: Specify a class type to use for a PDF, LaTeX or Beamer document.
  • <!-- [[HEADER]] -->: Add the option to add a custom header for the convertion to Beamer (the file should be in the same directory as the Pandoc file).
  • <!-- [[NORENDER]] -->: Option to not automatically start the associated program.

Note: these hints are processed by the plugin and are NOT part of Pandoc itself.

Templates

The Templates could be found in the "Styles" folder in the Pandoc plugin folder (in the package folder of Sublime Text). The version comes with a standard html and docx template (from the Pandoc Render plugin) and with an APA guideline DOCX template.

You can use your custom templates by specifying the path in addition of the template name in the option BIBSTYLE, DOCSTYLE, CLASS and HEADER.

Tables

Create a grid table in Pandoc is a laborious task. With Pandoc Academic you can create or extend existing grid tables easily.

The module will automatically add filling dashed and cross. The module will also automatically resize the columns widths based on the longest cell of each column. You can handle empty cells and extend an existing grid table.

Create a new table

To create a new table, just type your data with at least 2 spaces to separate the columns.

Example:

Conditions  Col1  Col2  Col3
Line 1  data1  data2  data3
Line 2  data4  data5  data6

Then select the data with your mouse and go to Tools > Pandoc Academic > Pandoc Table or use the shortcut CTL+SHIFT+ALT+t. You should see:

+------------+-------+-------+-------+
| Conditions | Col1  | Col2  | Col3  |
+============+=======+=======+=======+
| Line 1     | data1 | data2 | data3 |
+------------+-------+-------+-------+
| Line 2     | data4 | data5 | data6 |
+------------+-------+-------+-------+

The module will always consider the first line as the title line. If one or more cells should be empty just type NA in.

Extend an existing table

The module allows to extend an existing table. Just add the new data or modify the current one, and use the module:

+------------+-------+-------+-------+
| Conditions | Col1  | Col2  | Col3  | Col4
+============+=======+=======+=======+
| Line 1     | rename | data2 | data3 | data7
+------------+-------+-------+-------+
| Line 2     | data4 | long long data | data6 | data8
+------------+-------+-------+-------+

will become:

+------------+--------+----------------+-------+-------+
| Conditions | Col1   | Col2           | Col3  | Col4  |
+============+========+================+=======+=======+
| Line 1     | rename | data2          | data3 | data7 |
+------------+--------+----------------+-------+-------+
| Line 2     | data4  | long long data | data6 | data8 |
+------------+--------+----------------+-------+-------+

Path option

If Pandoc is not in the path of Sublime Text, you can specify a custom path in your file with the following command: [[PATH=path_name]].

If you want to change the path used by the plugin, you can edit the plugin file "PandocConvertor.py". Change the line 146:

cmd = ['pandoc']

with:

cmd = ['your_path']

Disclosure

I am an academic guy, not a software programmer or a computer guru. This plugin is therefore missing some features and could be improved. I try to do my best, but I need your feedbacks to help me to do so: [email protected]. In the same vein, if you're willing to help or to be involved in this project, your participation is more than welcome.

Thanks!

Guillaume

pandocacademic's People

Contributors

andreas-bok-sociomantic avatar dantonnoriega avatar erihe251 avatar jraygauthier avatar larlequin avatar scotartt avatar vehka avatar yyjhao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pandocacademic's Issues

html comment highlighting leaks

I use html comments heavily on my pandoc documents. The syntax highlighting for them breaks when there's two of them in the same row:

test

In the example above, the whole line gets highlighted as a comment.

Syntax Highlight is not working in the following case

Hi larlequin,
I am making note using PandocAcademic. Unfortunately, the syntax works not so good for the following case.

The relational operators are> >= < <= They all have the same precedence. Just below them in precedence are the equality operators: == !=. Relational operators have lower precedence than arithmetic operators, so an expression like i < lim-1 is taken as i < (lim-1) , as would be expected.

I just want to let you know about this. Not a big deal, so no worry.

Rax

cannot convert to pdf/beamer

It successfully converts to .html or .docx, but shows no response when attempting to convert to pdf or beamer.

I checked the 'PandocConverter.py' file, but could not find any module dealing with 'convert to pdf' functionality.

Could you confirm that??

no output

I get the following error (in Linux), no matter which conversion-format is chosen, with the result of no file/nothing opened:

File "./sublime_plugin.py", line 356, in run_
File "./PandocConvertor.py", line 203, in run
File "./PandocConvertor.py", line 167, in buildCommand
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 20: ordinal not in range(128)

What does that mean?

Some images are not shown in html

If I convert the markdown using pandoc from the command line all the images are there, but using the conversion of pandoc academic some get lost.

This is the url of a image I can view
file:///home/leonardo/Dropbox/LabBiologia/LOF/figs/LaBio05_molec.png

And this is the url of a image I can not
file:///home/leonardo/Dropbox/LabBiologia/LOF//home/leonardo/Dropbox/LabBiologia/LOF/figs/LaBio06_filo.png

Where do the files output

Sorry, can't seem to find anything in the docs that tell us where the default output for a conversion goes - nor how to set that for ourselves. Thanks.

Unable to find pandoc executable when using on Mac OS (brew)

Hi,
I have pandoc installed via brew install pandoc on MacOS Sierra.
When I try to execute the PDF conversion, I will get this error:
image

It seems that it cannot find the pandoc and xdg-open executable, here is the stacktrace from the Sublime

error: Unable to execute Pandoc.                                    

Details: [Errno 2] No such file or directory: 'pandoc'
Unable to convert the file! Please check your options
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 812, in run_
    return self.run(edit, **args)
  File "PandocConvertor in /Users/maddis/Library/Application Support/Sublime Text 3/Installed Packages/Pandoc Academic.sublime-package", line 217, in run
  File "./python3.3/subprocess.py", line 523, in call
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1448, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: 'xdg-open'

pandoc is available in the PATH when using the terminal. Also the equivalent to using xdg-open on MacOS is the open command, maybe there could be a switch statement based on the OS.

path issues

I've been having a struggle working out how subprocess is getting the $PATH for the pandoc and pdflatex executables. I've now symlinked pandoc and pdflatex to /usr/bin, but it feels like I shouldn't have to... Would it also be possible to have a setting to include paths which will be dropped into environ.os['PATH'']? This was users can specify where their pandoc executable is... mine is installed via cabal so in ~/.cabal/bin, and pdflatex is in some crazy place that texlive puts it. They're on my bash PATH, but not seen by subprocess.

Package is not working on Mac 10.13.6

The problem seems to be related to xdg-open that is not a native mac command. I attach here under the consol log

Unable to convert the file! Please check your options Traceback (most recent call last): File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 1066, in run_ return self.run(edit, **args) File "/Users/serg/Library/Application Support/Sublime Text 3/Installed Packages/Pandoc Academic.sublime-package/PandocConvertor.py", line 217, in run File "./python3.3/subprocess.py", line 523, in call File "./python3.3/subprocess.py", line 819, in __init__ File "./python3.3/subprocess.py", line 1448, in _execute_child FileNotFoundError: [Errno 2] No such file or directory: 'xdg-open' Unable to convert the file! Please check your options Traceback (most recent call last): File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 1066, in run_ return self.run(edit, **args) File "/Users/serg/Library/Application Support/Sublime Text 3/Installed Packages/Pandoc Academic.sublime-package/PandocConvertor.py", line 217, in run File "./python3.3/subprocess.py", line 523, in call File "./python3.3/subprocess.py", line 819, in __init__ File "./python3.3/subprocess.py", line 1448, in _execute_child FileNotFoundError: [Errno 2] No such file or directory: 'xdg-open'

Table won't render

I've tried to render your sample table without success. When I highlight the data and try to select Tools --> Pandoc Academic --> Pandoc Table, the Pandoc Table option is greyed out. Thoughts?

Syntax: Fenced Code Blocks

The current syntax definition for fenced code blocks does not match the documentation for Pandoc markdown. Instead of a simple ~~~ pair, similar to the backtick-style code blocks, I think the following regex would be a significant improvement:

begin

^~~~+(\s?[{].*[}])?$

end

^~~~+$

The begin regex will match a minimum of three tildes and allow for an optional list of parameters in braces; and it will end with a line consisting only of tildes, again with a minimum of three.

It would also be a nice touch to look into the braces for a recognized language name class, and syntax highlight the fenced code block accordingly.

Thanks!

Error converting to docx/html

I've installed PandocAcademic via Sublime Text Packages. When i create a new file and save it as ebook.pandoc and then click on Tools/Pandoc Convert/Convert to docx i have this error in the console:

Traceback (most recent call last):
  File ".\sublime_plugin.py", line 356, in run_
  File ".\PandocConvertor.py", line 145, in run
  File ".\PandocConvertor.py", line 129, in buildCommand
  File ".\PandocConvertor.py", line 101, in opt
  File ".\PandocConvertor.py", line 71, in template
  File ".\PandocConvertor.py", line 40, in getTemplatePath
Exception: reference.docx file not found!

I have the same issue with convert to html.

Thanks.

Path issues on Mac OS X

Strange things seem to happen with my Installation on Mac OS X 10.8.2

I I try to comple a testfile to HTML, i get following exception:

Template file found in the default template folder
error: Unable to execute Pandoc.                                    

Details: [Errno 2] No such file or directory
Unable to convert the file! Please check your options
Traceback (most recent call last):
  File "./sublime_plugin.py", line 356, in run_
  File "./PandocConvertor.py", line 217, in run
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/webbrowser.py", line 69, in open_new_tab
    return open(url, 2)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/webbrowser.py", line 61, in open
    if browser.open(url, new, autoraise):
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/webbrowser.py", line 549, in open
    ic.launchurl(url)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/ic.py", line 238, in launchurl
    return _dft_ic.launchurl(url, hint)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/ic.py", line 205, in launchurl
    self.ic.ICLaunchURL(hint, url, 0, len(url))
MacOS.Error: (-673, 'no URL found')
Template file found in the default template folder
error: Unable to execute Pandoc. 

Afterwords I tried to comple it to DOCX, which results in:

Details: [Errno 2] No such file or directory
Unable to convert the file! Please check your options
Traceback (most recent call last):
  File "./sublime_plugin.py", line 356, in run_
  File "./PandocConvertor.py", line 223, in run
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 470, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 623, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1141, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

This happens on a fresh install of Pandoc Academic via the Package Control Plugin.
Might this be related with spaces in pathnames or something similar?
My File is located under /Users/xxx/Documents/test.markdown and has following content:

Headline
========

+------------+-------+-------+-------+
| Conditions | Col1  | Col2  | Col3  |
+============+=======+=======+=======+
| Line 1     | data1 | data2 | data3 |
+------------+-------+-------+-------+
| Line 2     | data4 | data5 | data6 |
+------------+-------+-------+-------+

Title of TOC is always "Contents"

I'm created a PDF with markdown. I need a TOC so i used <!-- [[TOC]] -->.

The title of the TOC is always "Contents", which is pretty bad, if the documents content is another language.

How can i change the title of the table of contents, without editing code?

Sublime text 3 compatibility

Have you considered what it would take to make the plugin ST3 compatible? This is one of the few remaining plugins that prevent me from upgrading Sublime text. I might have some time to help, but I don't know much at all about the ST innards...

ValueError

Launched Sublime3 for a non-pandoc related project (PHP) and noticed the following error in the console.

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 444, in is_enabled_
    raise ValueError("is_enabled must return a bool", self)
ValueError: ('is_enabled must return a bool', <Pandoc Academic.Table_pandoc.PandocTableCommand object at 0x109972550>)

template not found

Hi
I've installed the plug-in on Sublime 3, under linux (ubuntu 16.04).

When I try to convert to any format, I get the following error:Traceback (most recent call last):

  File "/opt/sublime_text/sublime_plugin.py", line 1066, in run_
    return self.run(edit, **args)
  File "/home/ilafin01/.config/sublime-text-3/Installed Packages/Pandoc Academic.sublime-package/PandocConvertor.py", line 199, in run
  File "/home/ilafin01/.config/sublime-text-3/Installed Packages/Pandoc Academic.sublime-package/PandocConvertor.py", line 171, in buildCommand
  File "/home/ilafin01/.config/sublime-text-3/Installed Packages/Pandoc Academic.sublime-package/PandocConvertor.py", line 148, in opt
  File "/home/ilafin01/.config/sublime-text-3/Installed Packages/Pandoc Academic.sublime-package/PandocConvertor.py", line 101, in template
  File "/home/ilafin01/.config/sublime-text-3/Installed Packages/Pandoc Academic.sublime-package/PandocConvertor.py", line 54, in getTemplatePath
Exception: template.html file not found!

Looking at the Plug-ins folder of sublime, it seems that it is not un-zipping the files, so the path should be

/home/ilafin01/.config/sublime-text-3/Installed Packages/Pandoc Academic.sublime-package/

I've looked at the PandocConvertor.py script, and it appends only "Pandoc Academic". Should probably with the ".sublime-package" addition.

How to add references?

Hi @larlequin,

Many thanks for PandocAcademic! I used the command provided to convert my document to PDF.

However, it does not convert my references.

My frontmatter contains the following:

---  
title: title...
abstract: abstract....
date: December 15, 2014
bibliography: /home/orschiro/Mendeley/library.bib
csl: APA6.csl
---  

In the end of my document I added #References.

My references are successfully added when using the following command in my Linux shell:

pandoc -S -o output.pdf --filter pandoc-citeproc document.md

Is there any way to customise the provided Pandoc command to use the --filter pandoc-citeproc option?

Thanks for your advice!

Robert

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.