pandoc-mode
is an Emacs mode for interacting withPandoc. Pandoc is a program (plus libraries)created by John MacFarlane that can convert a text written in one markuplanguage into another markup language. pandoc-mode
is implemented as aminor mode that can be activated alongside the major mode for any ofPandoc’s supported input formats. It provides facilities to set thevarious options that Pandoc accepts and to run Pandoc on the input file.It is possible to create different output profiles for a single inputfile, so that you can, for example, write your text in Markdown and thentranslate it to HTML for online reading, PDF for offline reading andTexinfo for reading in Emacs, all with just a few keystrokes.
The current version of pandoc-mode
is 2.31 and is compatible withPandoc 2.12.
Pandoc -s -o doc.pdf doc.md. Pandoc is able to merge multiple Markdown files into a single PDF document. To generate a single PDF document out of two Markdown files you can use: pandoc -s -o doc.pdf part01.md part02.md. By default the page margins in the resulting PDF document are quite large. You can change this by passing a margin parameter. Markdown, Latex, Pandoc. Homebrew 사용하여 설치: brew install pandoc Markdown - Latex pandoc text.md -o test.pdf -pdf-engine=xelatex -V papersize:a4.
The easiest way to install pandoc-mode
is to use theMelpa package repository.
In order to activate pandoc-mode
in a buffer, you need to typeM-x pandoc-mode
. To start pandoc-mode
automatically when you loade.g., a Markdown file, you can add a hook to your init file:
However, if you do not want to start pandoc-mode
every time you workon a Markdown document, you can use a different function inmarkdown-mode-hook
: instead of using pandoc-mode
, you can useconditionally-turn-on-pandoc
. This function checks if a defaultsettings file exists for the file you’re opening and only turns onpandoc-mode
if it finds one. (For more info on the settings file, seethe section ‘Settings Files’.)
Additionally, if you want to automatically load the defaultpandoc-mode
settings file for the file you’re opening, you can add thefollowing to your init file:
The function pandoc-load-default-settings
checks if a default settingsfile exists for the file being loaded and reads its settings if it findsone.
OS X
pandoc-mode
expects that the pandoc
binary can be found in yoursystem’s $PATH
and that the contents of $PATH
is available to Emacs.Especially on OS X, this may not always be the case. To remedy this, youcan set the user option pandoc-binary
to the full path of pandoc
onyour system. A more elegant solution is to install theexec-path-from-shellpackage. This package makes sure that the contents of your system’s$PATH
variable is visible to Emacs, allowing Emacs to find pandoc
.
pandoc-mode
uses the hydra packageto create a keyboard-driven menu interface to all options and settings.The main menu is called by pressing C-c /
. After that, everythingshould be self-explanatory. From the main menu, you can run pandoc
onthe buffer, view the output buffer and the current settings, set theinput and output formats, and you can go to the options menu.
Note that if the menu bar is active, pandoc-mode
also provides a menuin the menu bar. It has the same structure as the hydra menu and it hasthe advantage that options that do not apply to the current file (due toits input or output format), are generally greyed out. On the otherhand, the hydra menu shows the value of the options and allows you tochange more than one option without having to keep reopening the menu.The menu bar menu disappears when you select an option, the hydra menu(generally) does not. Instead, it can be dismissed with q
. Below, Italk about the hydra menu specifically, but most of what is said appliesto the menu bar menu as well.
In the options menu, you can set options for running pandoc
on yourinput file. All Pandoc options can be set from the menu (except for oneor two that do not make sense, e.g., --print-default-template
). Notethat when you set options, they only apply to the current file and thecurrent output format. When you open another file, or when you changethe output format, all settings are reset to their default values.(There are ways to make settings more permanent, of course, as discussedbelow.)
Input and output formats
The most important settings are the input and output formats. The inputformat is set automatically by Emacs on the basis of the major mode ofthe input file, but you can change it if you need to. The output formatdefaults to “Native Haskell”, so most likely you will want to set it tosomething else before you run Pandoc. The input and output format menusalso provide access to a submenu with the Markdown extensions thatPandoc supports.
As already stated, you may wish to use different output formats for asingle input file. Most likely, the options that you want to pass toPandoc will be different for each output format. To make this easier,pandoc-mode
has the ability to save the settings for a specific outputformat. The main menu has an option “Settings files” (C-c / s
), whichtakes you to a submenu where you can save the current settings. Emacssaves these settings to a hidden file in the same directory as the fileyou’re editing, under a name composed of the input file, appended withthe name of the output format and the string .pandoc
. So if your inputfile is called mytext.md
, the html
settings file will be called.mytext.md.html.pandoc
. (See the section ‘SettingsFiles’ for details.)
A single document can have a separate settings file for each outputformat that Pandoc supports. These can simply be created by setting alloptions the way you want them for the first output format, save them,then choose another output format, set the required options, save again,etc. Because the name of a settings file contains the output format forwhich it was created, the different settings files won’t interfere witheach other. When you switch the output format (with C-c / O
), Emacschecks if a corresponding settings file exists and loads it if one isfound.
On systems that have symbolic links, it is also possible to specify adefault output format (C-c / s d
). This is done by creating a symboliclink to the settings file of the current output format (a settings fileis created if one doesn’t exist yet) with the output format replaced bythe string 'default'
. The file it points to is read by the functionpandoc-load-default-settings
, making it possible to automatically loada specific settings file when pandoc-mode
is invoked, as describedabove.
Note that the current output format is always visible in the mode line:the “lighter” for pandoc-mode
in the mode line has the formPandoc/<format>
, where <format>
is the current output format.
The major modes for which pandoc-mode
selects an input formatautomatically can be customised (user option pandoc-major-modes
). Youcan add major modes or remove those that you don’t use. Similarly, youcan customise the file extensions for each output format(pandoc-output-format-extensions
).
The options menu
The options menu has a number of submenus, each related to a specifictype of options: file options, reader options, writer options (generaland specific), citations and math rendering. The file options menucontains options for the output file, output directory, data directory,the directory to extract media files to, and the master file. Only twoof these (the data directory and the extract media directory) corresponddirectly to a Pandoc option. The output file and output directoryoptions are combined to form Pandoc’s --output
option, while themaster file option is only used by pandoc-mode
. These options arediscussed in the sections ‘Setting an outputfile’ and ’Master file’,respectively.
Note that the subdivision in the options menu is based on thesubdivision in the Pandoc README and the user guide onPandoc.org, which should make it easierto find the relevant options in the menus. pandoc-mode
supports Pandocversion 1.x and version 2.x: options that are only valid in Pandoc 1.xare marked with an asterisk. (Options that only exist in Pandoc 2.xaren’t marked.)
One nice thing about the hydra menus is that the value of an option isdisplayed beside it. Pandoc’s options come in several different kinds.Switches, (boolean options that do not take a value), are toggled whenyou select them, and their value is displayed as either “yes” or “no”.If you select another kind of option, you are asked to provide a valuein the minibuffer. For template variables and metadata items, you areasked both a variable / metadata name and a value.
Unsetting an option can usually be done by prefixing the relevant keywith a dash -
. This is actually the negative prefix argument, whichcan be typed without the meta (alt) key when inside a hydra menu. So forexample, if you’re in the files menu (C-c / o f
), you can set anoutput file with o
, and to unset the output file, you can type - o
.
Many Pandoc options have file names as values. These are normallyprompted for and stored as relative paths. File name completion isavailable, starting from the current directory. For some options, suchas --css
, relative paths make more sense because an absolute filewould almost certainly be incorrect once the output html file is movedto the web server. Other options, such as --template
, look in Pandoc’sdata directory and therefore also do not require an absolute path.Lastly, auxiliary files, such as --include-in-header
, will usually bestored in the same directory as the source file or in a subdirectory, inwhich case a relative path is unproblematic.
However, if for some reason you need to store an absolute path for anoption, you can do so by using the prefix argument C-u
. So for examplein the general writer options menu, accessible through C-/ o w
,pressing C-u H
asks for a file to include in the header and stores itas an absolute path. Note that absolute paths are not expanded, i.e.,they may contain abbreviations such as ~
for one’s home directory.This makes it easier to share settings files between computers withdifferent OSes (for example, Linux expands ~
to /home/<user>
, whileon OS X it becomes /Users/<user>
).
Note that if you use a minibuffer completion framework (such asIvy orHelm), file name completion maywork differently. Ivy, for example, always expands file names.
Some file options (such as --epub-stylesheet
) may have a defaultvalue. Such options can be specified on the pandoc
command linewithout naming a file. To select such a default value for a file option,use a numeric prefix argument, which in the hydra menu is obtained bypressing a number without the meta key. That is, to select the defaultEPUB style sheet, go to the EPUB options menu (C-/ o s E
) and press1 s
.
Options that are not files or numbers are “string options”, whichinclude options that specify a URL. These may also have a default value,which can be set in the same way as with file options. Note, though,that this does not apply to options that only have a limited set ofpossible values (e.g., --email-obfuscation
, --pdf-engine
). These canbe set or unset, you cannot explicitly request their default value.(`pandoc’ uses their default values even if they are not specified onthe command line, unlike string options.)
To get an overview of all the settings for the current file and outputformat, you can use the option “View current settings” in the main menu(C-c / S
). This displays all settings in a *Help*
buffer in aLisp-like format. For example, the settings for TeXinfo output of thismanual look like this:
Template variables and metadata
pandoc-mode
allows you to set or change template variables through themenu. The variables are in the general writer options menu, the metadatain the reader options menu. Emacs will ask you for the name of avariable or metadata item and for a value for it. If you provide a namethat already exists (TAB completion works), the new value replaces theold one.
Deleting a template variable or metadata item can be done by prefixingthe menu key with -
. Emacs will ask you for the variable name (TABcompletion works here, too) and removes it from the list.
Running Pandoc
The first item in the menu is “Run Pandoc” (accessible with C-c / r
),which, as the name suggests, runs Pandoc on the document, passing alloptions you have set. By default, Pandoc sends the output to stdout(except when the output format is “odt”, “epub” or “docx”, in which caseoutput is always sent to a file). Emacs captures this output andredirects it to the buffer *Pandoc output*
. The output buffer is notnormally shown, but you can make it visible through the menu or bytyping C-c / V
. Error messages from Pandoc are also displayed in thisbuffer.
Java jre for mac download. When you run Pandoc, pandoc-mode
also generates a few messages, whichare logged in a buffer called *Pandoc log*
. You will rarely need tosee this, since pandoc-mode
displays a message telling you whetherPandoc finished successfully or not. In the latter case, the outputbuffer is displayed, so you can see the error that Pandoc reported.
Note that when you run Pandoc, Pandoc doesn’t read the file on disk.Rather, Emacs feeds it the contents of the buffer through stdin
. Thismeans that you don’t actually have to save your file before runningPandoc. Whatever is in your buffer, saved or not, is passed to Pandoc.Alternatively, if the region is active, only the region is sent toPandoc.
If you call this command with a prefix argument C-u
(so the keysequence becomes C-/ C-u r
: C-/
to open the menu and C-u r
to runPandoc), Emacs asks you for an output format to use. If there is asettings file for the format you specify, the settings in it will bepassed to Pandoc instead of the settings in the current buffer. If thereis no settings file, Pandoc will be called with just the output formatand no other options.
Note that specifying an output format this way does not change theoutput format or any of the settings in the buffer, it just changes theoutput profile used for calling Pandoc. This can be useful if you usedifferent output formats but don’t want to keep switching betweenprofiles when creating the different output files.
Setting an output file
If you want to save the output to a file rather than have it appear inthe output buffer, you can set an explicit output file. Note thatsetting an output file is not the same thing as setting an outputformat (though normally the output file has a suffix that indicatesthe format of the file).
In pandoc-mode
, the output file setting has three options: the defaultis to send output to stdout, in which case it is redirected to thebuffer *Pandoc output*
. This option can be selected by typing - o
inthe file options menu. Alternatively, you can let Emacs create an outputfilename for you. In this case the output file will have the same basename as the input file but with the proper suffix for the output format.To select this option, prefix the output file key o
with C-u
in thefile options menu. The third option is to specify an explicit outputfile. This can (obviously) be done by hitting just o
.
Note that Pandoc does not allow output to be sent to stdout if theoutput format is an OpenOffice.org Document (ODT), EPUB or MS Word(docx) file. Therefore, Emacs will always create an output filename inthose cases, unless of course you’ve explicitly set an output fileyourself.
The output file you set is always just the base filename, it does notspecify a directory. Which directory the output file is written todepends on the setting “Output Directory” (which is not actually aPandoc option). Emacs creates an output destination out of the settingsfor the output directory and output file. If you don’t specify anyoutput directory, the output file will be written to the same directorythat the input file is in.
Creating a pdf
The second item in the main menu is “Create PDF” (invoked withC-c / p
). This option calls Pandoc with a PDF file as output file.Pandoc offers different ways of creating a PDF file: you can use LaTeX,an HTML-to-PDF converter, or groff. Which method is used depends on theoutput format you specify, because Pandoc creates a PDF file by firstconverting your input file to the specified output format and thencalling the pdf converter on the output file.
When creating a PDF using pandoc-mode
, Emacs first checks if theoutput format of the current buffer is set to latex
, context
,beamer
, html
, or ms
. If it is, C-c / p
creates the PDF usingthat format. If you want to bypass this automatic detection, use aprefix argument C-u
(i.e., type C-c / C-u p
). Emacs will then askyou for the output format to use.
If the buffer’s current output format does not allow for PDF creation,Emacs will ask you which output format to use. If there is a settingsfile for the output format you specify, it is used to create the PDF.(The current buffer’s settings aren’t changed, however.) If there is nosettings file, Pandoc is called with only the input and output formatsand the output file.
The format you choose is remembered (at least until you close the bufferor change the output format), so that the next time you convert thebuffer to PDF, you are not asked for the format again. If you want touse a different format, use the prefix argument C-u
.
This setup means that you do not need to switch the output format tolatex
, context
or html5
every time you wish to create a PDF, whichcan be practical if you’re also converting to another format. However,if you wish to change settings for PDF output, you do need to switchto the relevant output format.
Note that for latex
, beamer
and html
, you can use different PDFengines. For latex
and beamer
, these are pdflatex
(the default),xelatex
and lualatex
, for html
there are wkhtmltopdf
(thedefault), weasyprint
and prince
. If you wish to use a PDF engineother than the default, you need to set the option pdf-engine
.
Viewing the output
After running Pandoc, you can view the output file with the optionView output file
in the menu (or C-c / v
). Emacs will try to displaythe file created during the most recent Pandoc run. Which viewer is usedto display the output file depends on the output format (not on theoutput file’s extension, so that you can use different viewers fordifferent output formats, even if their file extensions are identical.For example, docbook
, jats
and tei
all use xml
as the fileextension, but you may not want to use the same viewer for all of them).
Viewers are defined in the customisation option pandoc-viewers
. Thereare three types of viewers: you can choose to use Emacs itself as thefile viewer, in which case the output file is opened in Emacs anddisplayed using display-buffer
. It is also possible to define anexternal viewer, which should then be a program that takes a fileargument on the command line. For example, word processor formats(odt
, docx
) and Powerpoint presentations (pptx
) are by defaultopened in LibreOffice, which can be called with the shell commandlibreoffice <filename>
.
Lastly, it is also possible to specify a specific Emacs function tohandle the file. This should be a function that takes a file name asargument. The function can pass on the file to an external program(HTML-based formats, for example, are by default handled by the functionbrowse-url
, which sends the file to a suitable browser), or it canarrange to open the file in Emacs, if the standard find-file-noselect
is not suitable. Note, though, that if you choose this method, youshould also make sure that your function not only opens the file butalso displays its buffer (e.g., using display-buffer
).
If the most recent call to Pandoc created a pdf file (i.e, the option“Convert to pdf” was called), Emacs will display the pdf file instead ofthe output file defined by the output file/directory options. The viewerto use in this case is defined by the option pandoc-pdf-viewer
, whichcan be Emacs (which will then use doc-view-mode, or
pdf-tools` ifinstalled) or an external program.
Note that this functionality is not as full-featured as with e.g.,AUCTeX and SyncTeX. There is no forward or backward search and whathappens when you view a file when an earlier version of that file isalready open in some application is up to that application. Emacs willusually notice that the file has changed on disk and will ask you if youwant to reload it. Pdf viewers will generally behave correctly (thatincludes pdf-tools
in Emacs) and simply reload the file withoutasking.
If you want to open the output file automatically after conversion, youcan add the function pandoc-view-output
topandoc-async-success-hook
. As the name of the hook implies, this onlyworks if you call Pandoc asynchronously —cf. the optionpandoc-use-async
— but this is the default and there is usually littlereason to change it.
If you try to view an output file before calling Pandoc (e.g., afterreopening the input file), Emacs will try to display the output filedefined by the output directory
and output file
settings. If nooutput file is defined at all (which means that Pandoc does not createan output file but instead sends its output to standard out), Emacs willshow the *Pandoc output*
buffer, which is where the output of the callto Pandoc is captured.
If the most recent Pandoc run returned an error, trying to view theoutput file will result in an error as well, unless you provide a prefixargument (C-c / C-u v
), in which case Emacs will try to display theoutput file defined by the output directory
and output file
settings.
Connection Type
By default, Emacs starts pandoc
as an asynchronous process using atty. If this causes problems for some reason, you can try using a pipeinstead by customising pandoc-process-connection-type
. Alternatively,you can use a synchronous process by unsetting the user optionpandoc-use-async
.
Pandoc Pdf Margin
Citation Jumping
pandoc-mode
provides the function pandoc-jump-to-reference
thatlocates a reference within external bibliography files indicated by thebibliography
user option. Note that entries to the bibliography
useroption list must have an absolute path for this option to work properly(i.e. './Bibliography.bib'
rather than 'Bibliography.bib'
). Thisfeature is not bound to any key by default, but may of course be boundto a key combination as follows:
The jump behaviour can be customised by changing the optionpandoc-citation-jump-function
. Its default value ispandoc-goto-citation-reference
, which opens the relevant BibTeX filein a new window and moves point to the entry. Two alternative functionshave been defined: pandoc-open-in-ebib
, which opens the relevant entryin Ebib, and pandoc-show-citation-as-help
, which shows the entry in a*Help*
buffer, but does not open the corresponding BibTeX file.
Alternatively, you may also define your own function, which should taketwo arguments: the key of the entry to be displayed and a list of BibTeXfiles.
pandoc-mode
adds font lock keywords for citations and numbered examplelists. The relevant faces can be customised in the customisation grouppandoc
.
Apart from settings files for individual files (which are called localsettings files), pandoc-mode
supports two other types of settingsfiles: project files and global files. Project files are settings filesthat apply to all input files in a given directory (except those filesfor which a local settings file exists). Global settings files, as thename implies, apply globally, to files for which no local or projectfile is found. Both types of files are specific to a particular outputformat, just like local settings files. Project files live in thedirectory they apply to and are called Project.<format>.pandoc
. Globalfiles live in the directory specified by the variable pandoc-data-dir
,which defaults to ~/.emacs.d/pandoc-mode/
, but this can of course bechanged in the customisation group pandoc
.
Whenever pandoc-mode
loads settings for an input file, it first checksif there is a local settings file. If none is found, it looks for aproject file, and if that isn’t found, it tries to load a globalsettings file. In this way, local settings override project settings andproject settings override global settings. Note, however, that if alocal settings file exists, all settings are read from this file. Anyproject file or global file for the relevant output format is ignored.
You can create a project or global settings file through the menu in thesubmenu “Settings Files”. This simply saves all settings for the currentbuffer to a project or global settings file. (Any local settings filefor the file in the current buffer will be kept. You’ll need to deleteit manually if you no longer need it.)
The name of a global settings file has the form <format>.pandoc
, where<format>
obviously specifies the output format. <format>
can also bethe string 'default“
, however, in which case it specifies a defaultsettings file, which is loaded by pandoc-load-default-settings
when nodefault local or project settings file is found. In this way, you canoverride the default output format used for new files.
One thing to keep in mind is that the method in which pandoc-mode
saves settings and passes them to the pandoc
binary is not compatiblewith Pandoc’s YAML metadata blocks/files or with Pandoc’s defaults file.Since pandoc-mode
passes all settings to pandoc
as command-lineoptions, they override settings in defaults files and in YAML metadatablocks or files. You should generally stick to using one or the othermethod.
pandoc-mode
also allows options to be set as file-local variables,which gives you the ability to keep the settings for a file in the fileitself. To specify an option in this way, use the long form of theoption as a variable name, prefixed with pandoc/
(note the slash; usepandoc/read
and pandoc/write
for the input and output formats, andpandoc/table-of-contents
for the TOC).
For example, in order to set a bibliography file, add the following lineto the local variable block:
The easiest way to add a file-local variable is to use the commandM-x add-file-local-variable
. This will put the variable at the end ofthe file and add the correct comment syntax. Note that the values areLisp expressions, which means that strings need to be surrounded withdouble quotes. Symbols do not need to be quoted, however.
Settings specified as file-local variables are kept separate from othersettings: they cannot be set through the menu and they are never savedto a settings file. When you call pandoc-view-settings
(C-c / S
),they are shown in a separate section. A source file can both have asettings file and specify settings in file-local variables. If thishappens, the latter override the former.
Note that it is also possible to specify the customisation optionpandoc-binary
as a file-local variable. It does not require thepandoc/
prefix, but since its value is a string, it must be enclosedin quotes:
Pandoc provides a method for creating examples that are numberedsequentially throughout the document (see Numbered examplelists in thePandoc documentation). pandoc-mode
makes it easier to manage suchlists. First, by going to “Example Lists | Insert New Example”(C-c / e i
), you can insert a new example list item with a numericlabel: the first example you insert will be numbered (@1)
, the second(@2)
, and so on. Before inserting the first example item, Emacs willsearch the document for any existing definitions and number the newitems sequentially, so that the numeric label will always be unique.
Pandoc allows you to refer to such labeled example items in the text bywriting (@1)
and pandoc-mode
provides a facility to make thiseasier. If you select the menu item “Example Lists | Select And InsertExample Label” (C-c / e s
) Emacs displays a list of all the(@)
-definitions in your document. You can select one with the up ordown keys (you can also use j
and k
or n
and p
) and then hitreturn
to insert the label into your document. If you change yourmind, you can leave the selection buffer with q
without insertinganything into your document.
pandoc-mode
includes a facility to make specific, automatic changes tothe text before sending it to Pandoc. This is done with so-called@@
-directives, which trigger an Elisp function and are then replacedwith the output of that function. A @@
-directive takes the form@@directive
, where directive
can be any user-defined string (seeHow to define directive strings). Before Pandocis called, Emacs searches the text for these directives and replacesthem with the output of the functions they call.
So suppose you define (e.g., in ~/.emacs.d/init
) a functionmy-pandoc-current-date
:
Now you can define a directive @@date
that calls this function. Theeffect is that every time you write @@date
in your document, it isreplaced with the current date.
Note that the function that the directive calls must have one argument,which is used to pass the output format to the function (as a string).This way you can have your directives do different things depending onthe output format. This argument can be called anything you like. In theabove example, it is called _
(i.e., just an underscore), to indicatethat the variable is not actually used in the function. If you do useit, you should probably choose a more meaningful name.
@@
-directives can also take the form @@directive{..}
. Here, thetext between curly braces is an argument, which is passed to thefunction called by the directive as the second argument. Note that thereshould be no space between the directive and the left brace. If thereis, Emacs won’t see the argument and will treat it as normal text.
It is possible to define a directive that can take an optional argument.This is simply done by defining the argument that the directive’sfunction takes as optional. Suppose you define my-pandoc-current-date
as follows:
This way, you could write @@date
to get just the date, and@@date{Cologne}
to get “Cologne, @@date”.
Two directives have been predefined: @@lisp
and @@include
. Both ofthese take an argument. @@lisp
can be used to include Elisp code inthe document which is then executed and replaced by the result (whichshould be a string). For example, another way to put the current date inyour document, without defining a special function for it, is to writethe following:
Emacs takes the Elisp code between the curly braces, executes it, andreplaces the directive with the result of the code. Download full games for free mac. Note that the codecan be anything, and there is no check to see if it is “safe”.
@@include
can be used to include another file into the currentdocument (which must of course have the same input format):
This directive reads the file copyright.text
and replaces the@@include
directive with its contents.
Processing @@
-directives works everywhere in the document, includingin code and code blocks, and also in the %-header block. So by puttingthe above @@lisp
directive in the third line of the %-header block,the meta data for your documents will always show the date on which thefile was created by Pandoc.
If it should ever happen that you need to write a literal '@@lisp'
inyour document, you can simply put a backslash before the first @
:@@lisp
. Emacs removes the backslash (which is necessary in case thestring @@lisp
is contained in a code block) and then continuessearching for the next directive.
After Emacs has processed a directive and inserted the text it producedin the buffer, processing of directives is resumed from the start ofthe inserted text. That means that if an @@include
directive producesanother @@include
directive, the newly inserted @@include
directive gets processed as well.
Master file
If you have a master file with one or more @@include
directives andyou’re editing one of the included files, running Pandoc from thatbuffer will not produce the desired result, because it runs Pandoc onthe included file. To make working with included files easier, you canspecify a master file for them, with the commandpandoc-set-master-file
(through the menu with C-c / o f m
). Whenthis option is set, Pandoc is run on the master file rather than on thefile in the current buffer.
The settings used in this case are always the settings for the masterfile, not the settings for the included file. The only exception is theoutput format, which is taken from the buffer from which you run Pandoc.This makes it possible to change the output format while in a buffervisiting an included file and have pandoc-mode
do the right thing.
One thing to keep in mind is that the master file setting is dependenton the output format. When you set a master file, it is only set for theoutput format that is active. This means that you need to set the outputformat before you set the master file.
Note that the master file menu also has an option “Use this file asmaster file” (C-c / o f M
). When you select this option, the currentfile is set as master file and a project settings file is created forthe current output format. This is a quick way to set the master filefor all files in a directory, since the project settings will apply toall files in the directory.
Defining @@-directives
Defining @@
-directives yourself is done in two steps. First, you needto define the function that the directive will call. This function musttake at least one argument to pass the output format and may take atmost one additional argument. It should return a string, which isinserted into the buffer. The second step is to go to the customisationbuffer with M-x customize-group
RET
pandoc
RET
. One of theoptions there is pandoc-directives
. This variable contains a list ofdirectives and the functions that they are linked with. You can add adirective by providing a name (without @@
) and the function to call.Note that directive names may only consists of letters (a-z
, A-Z
) ornumbers (0-9
). Other characters are not allowed. Directive names arecase sensitive, so @@Date
is not the same as @@date
.
Pandoc Pdf
Passing more than one argument to an @@
-directive is not supported.However, if you really want to, you could use split-string
to splitthe argument of the @@
-directive and “fake” multiple arguments thatway.
Pandoc Pdf Template
A final note: the function that processes the @@
-directives is calledpandoc-process-directives
and can be called interactively. This may beuseful if a directive is not producing the output that you expect. Byrunning pandoc-process-directives
interactively, you can see whatexactly your directives produce before the resulting text is sent topandoc. The changes can of course be undone with M-x undo
(usuallybound to C-/
).
Directive hooks
There is another customisable variable related to @@
-directives:pandoc-directives-hook
. This is a list of functions that are executedbefore the directives are processed. These functions are not supposedto change anything in the buffer, they are intended for setting upthings that the directive functions might need.
The hydra package provides a nice way to control pandoc-mode
and toset all the options that Pandoc provides. However, if for some reasonyou prefer to use normal key bindings, you can disable the hydra menu byrebinding C-c /
. To restore the original key bindings, put thefollowing in your init file:
It’s also possible to bind other commands to keys. The switches (i.e.,the options that can only be on or off) can be toggled with the commandpandoc-toggle-interactive
. All other options (except --read
) havededicated functions to set them, called pandoc-set-<option>
, where<option>
corresponds to the long form of the option without the doubledashes (use write
rather than to
, and table-of-contents
ratherthan toc
).