1

I'm writing company internal documentation in R markdown and compiling using knitr in Rstudio. I'm trying to add a link pointing to a directory as follows:

[testdir](file:////c:/test/)

(this is following the convention described in here)

When I compile it to html, I get the following link.

<a href="file:////c:/test/">testdir</a>

and it works as expected in Internet explorer. However, when I try to convert to pdf straight from RStudio, an unwanted pdf extension is appended to the link. I tried dissecting the problem and it seems this change is happening within pandoc. Here are the details.

When I convert it to latex using pandoc,

>pandoc -f markdown -t latex testing.md -o test.tex

the link in the latex output file looks as follows:

\href{file:///c:/test/}{testdir}

Everything good so far. However, when I convert the latex output to pdf with pandoc,

>pandoc -f latex -t latex -o test.pdf test.tex

a .pdf extension is appended to the link. Here is a copy/paste of the pdf link output:

/c:/test/.pdf

is there a way to avoid this unwanted appended extension?

Perhaps I'm asking too much of pandoc, but I thought it might be worth asking since RStudio is becoming such a useful IDE to write my dynamic documents.

Community
  • 1
  • 1
JAponte
  • 1,508
  • 1
  • 13
  • 21

1 Answers1

2

As you said, the .tex file pandoc generates is fine. So the problem is actually with LaTeX, specifically with the hyperref package which is used in pandoc's LaTeX template.

The problem with two possible solutions was described here. To prevent hyperref from being smart and adding a file extensions, try:

[testdir](file:///c:/test/.)

Or use ConTeXt instead of LaTeX:

$ pandoc -t context -s testing.md -o test.tex && context test.tex
Community
  • 1
  • 1
mb21
  • 34,845
  • 8
  • 116
  • 142
  • Thanks for the suggestion. I'll report when I try it. I've been distracted by more pressing projects. And of course, documentation took the back seat. – JAponte Dec 13 '14 at 20:51
  • I was able to test this today and it worked like a charm. Thanks @mb21 ! – JAponte Mar 17 '15 at 19:19