17

I am trying to add a custom latex template for pandoc

I know that pandoc templates go in ~/.pandoc/templates

and I confirmed the pandoc directory location by typing pandoc --v - it says pandoc is in ~/.pandoc

but when I do cd ~/.pandoc:

-bash: cd: /Users/[Name]/.pandoc: No such file or directory

According the pandoc man page I can set a different path for pandoc data files using --data-dir=DIRECTORY, but when I try build a file this way, e.g.

pandoc file.md -o file.pdf --data-dir=~/Library/texmf/tex/latex --template=mytemplate.latex

it throws the error

pandoc: Could not find data file templates/mytemplate.latex

which I assume means the data directory command is ignored.

Why can't I access my pandoc directory?

invictus
  • 1,821
  • 3
  • 25
  • 30
  • 2
    How about creating the expected directory? `mkdir ~/.pandoc` Maybe you are using a non-standard shell that doesn't understand `~`, try using `$HOME` in place of `~` maybe. – Mark Setchell Sep 26 '16 at 16:17
  • ~ works fine - for example ~/.jupyter takes me to jupyter – invictus Sep 26 '16 at 16:38

1 Answers1

18

You are indeed expected to create the ~/.pandoc directory if it doesn't exist already. For example for a default latex template:

mkdir -p ~/.pandoc/templates
pandoc -D latex > ~/.pandoc/templates/default.latex

The --template option looks for files relative to the current directory (pwd), or "if not found, pandoc will search for it in the templates subdirectory of the user data directory" (~/.pandoc/templates for --data-dir=~/.pandoc, which is the default).

Which is where your error comes from as there's probably no file /Library/texmf/tex/latex/templates/mytemplate.latex.

mb21
  • 34,845
  • 8
  • 116
  • 142
  • whoah, I assumed that the directory already existed. why would I have to create it when it says it exists? anyway, creating the directory and putting the template inside worked fine. However, I still don't understand the directory direction problem. The template was indeed inside that path. – invictus Sep 27 '16 at 01:31
  • @cmc `mkdir ~/.pandoc/templates` gives `.pandoc: No such file or directory` in my macOS terminal, so that doesn't seem to be an option. – mb21 May 23 '17 at 13:30
  • 2
    @mb21 Did you edit out the -p? mkdir -p ~/.pandoc/templates – cmc May 23 '17 at 13:40