[TxMt] Re: A pandoc .txt to .pdf command in markdown bundle

René Schwaiger sanssecours at f-m.fm
Wed Dec 24 10:59:23 UTC 2014


Hi Gildas,

> On 24 Dec 2014, at 8:54 , Gildas Hamel <gweltaz at ucsc.edu> wrote:
> 
> I made a simple shell script and a similar system service via automator to turn .txt files into .pdf via xelatex. They work well but require a couple steps outside TextMate. It would be a great convenience to have a command in the markdown bundle that would add this capacity. I tried it but failed even when giving full path to pandoc and pandoc-citeproc which are in /usr/local/bin, or to xelatex. I have little knowledge in these matters and would appreciate any help.
> 
> Here is my little shell script:
> 
> #!/bin/sh
> pandoc -S --filter pandoc-citeproc --latex-engine=xelatex "${1}" -o  "${1}".pdf
> 
> My similar automator service:
> 
> PATH=$HOME/.cabal/bin:/usr/local/bin:/usr/texbin:$PATH
> for file in "$@"
> do
>    output=${file%%.*}.pdf
>    pandoc -S --filter pandoc-citeproc --latex-engine=xelatex "$file" -o "$output"
> done
> 
> The metadata at the head of my .md or .txt files give extra info, such as title, font, bibliography, as in:
> 
> ---
> title: My title  
> author: My Name  
> date: \today  
> mainfont: Hoefler Text  
> bibliography: /Users/me/Library/texmf/bibtex/bib/data.bib  
> ---
> 
> Any pointers towards making a markdown bundle command that accomplishes what the scripts above do would be great.
> —Gildas

Hi Gildas,

you could for example create a command containing the following code:

—

#!/bin/bash

PDF_PATH=`echo "${TM_FILEPATH}" | sed -E 's/\.[^\/]+$/\.pdf/'`
PDF_NAME=`basename "${PDF_PATH}"`
pandoc -S --latex-engine=xelatex "${TM_FILEPATH}" -o "${PDF_PATH}"
echo "PDF saved to ${PDF_NAME}"

—

using the options:

Name:            Generate PDF
Scope Selector:  text.html.markdown
Key Equivalent:  ⌥⌘
Save:            Current Document
Input:           Nothing
Output:          Show in Tool Tip
  Format:        Text
Caret Placement: After Output

I attached a bundle that should contain the command described above. Just double click it to install the bundle. If you have any questions, please feel free to ask.

Kind regards,
  René

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Pandoc.tmbundle.zip
Type: application/zip
Size: 2574 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20141224/186ae361/attachment.zip>


More information about the textmate mailing list