svmiller / stevetemplates

My collection of R Markdown templates, as an R package.
http://svmiller.com/stevetemplates
125 stars 22 forks source link

Article Template 2 - knitting error - related to \urlstyle? #1

Closed ian-adams closed 3 years ago

ian-adams commented 3 years ago

Trying to knit from the base Article (type 2) template is generating a LaTeX error, that seems to be related to the template itself. This error is not occurring in the Article (type 1) template, or any other non-package templates that I have tried:

! Undefined control sequence. l.40 \urlstyle {same} % disable monospaced font for URLs

Could it be coming from the {url} package, which is included in the {hyperref} package that's loaded in the header?

svmiller commented 3 years ago

I appreciate you having me look at the template again because there was some other weirdness I had left in there that I'm going to fix with a new update (i.e. R Markdown/Pandoc can punish you for commenting out code rather than outright removing it).

Re: the issue you raise. That really looks like a LaTeX thing and the nature of the error seems to suggest you may not have whatever LaTeX add-on is responsible for that \urlstyle{} function. That's effectively what "undefined control sequence" means as far as LaTeX errors go. There's a function in the document and LaTeX doesn't know what to do with it. FWIW, I don't have that on my end, which is why I can't reproduce it.

ian-adams commented 3 years ago

No problem, thanks for taking a look. FWIW, I have updated MikTex and double-checked that the underlying packages that are called by the template are there (I think it is just {url} that pulls that function). I'll fiddle around, thanks again.

svmiller commented 3 years ago

My pleasure. The problem is no one ever credibly accused LaTeX errors of being helpful or informative. :P

I did want to note that whereas article in {stevetemplates} is really a LaTeX document I cobbled into a Pandoc template, article2 is really the default R Markdown/Pandoc template to which I just made some cosmetic edits. Thus, my hunch is an error that appears there would probably appear in the default template as well. A lot of the same code is there. This appears to be the problematic passage of code in particular (lines 202-204).

\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
ian-adams commented 3 years ago

Yes I think you're right about where that error is throwing from. Somethings taking place between default markdown/pandoc though, because I can knit everything else I've tried, from minimal working examples of templates to previous, more complex published articles. Like you noted, LaTeX isn't exactly helpful in diagnosing, and while in the past I've usually been able to cobble together a solution, at this point I'm not doing so well with this one. Sometimes just coming back in a week will solve it, I'll hope for that!

corneliushennch commented 3 years ago

Hey @ian-adams,

have you figured out the problem? I came across the exact same problem using TinyTeX 2020 that I installed using the tinytex package. I can knit the original article ("first article") template perfectly, but not the article2 template.

svmiller commented 3 years ago

@corneliushennch For my own curiosity, did you install Yihui Xie's {tinytex} package through R and not install your boilerplate god-knows-how-large LaTeX? My process is the latter over the former and I'm wondering if that's what might be happening here. I know nothing about Yihui Xie's package other than its advertised light-weightness (sic). Even then, that package should have the "url" LaTeX library.

Also, that template is really just default Pandoc template + goodies whereas the article template is a LaTeX template hacked to minimally comply with R Markdown/Pandoc. Thus, my hunch is article2 is posing problems, so will the default LaTeX Pandoc template.

corneliushennch commented 3 years ago

Yes exactly. I just installed {tinytex} from CRAN, then ran tinytex::install_tinytex() and your {stevetemplates} from your repo. Normally {tinytex} or rather livetex installs all necessary packages automatically while knitting to PDF, but that doesn't seem to work now.

I actually just got it to work by myself now after installing the xurl LaTeX package manually via tinytex::tlmgr_install("xurl"). Now the article2 template renders perfectly!

svmiller commented 3 years ago

Glad that worked. I felt pretty comfortable that it was a LaTeX package issue and not a problem with the template, per se. I'm glad I can at least point to that possibility now when it comes up.

Thank you so much!

ian-adams commented 3 years ago

Oh my lord, it worked! Thank you @corneliushennch, that's a lifesaver.

@svmiller I think you're right about the issue being in the "god knows how large" miktex package that I have used before I started with tinytex. Using the manual install tinytex::tlmgr_install("xurl") solved it first time.

Thank you very much to both!

kam-hak commented 1 year ago

Yes exactly. I just installed {tinytex} from CRAN, then ran tinytex::install_tinytex() and your {stevetemplates} from your repo. Normally {tinytex} or rather livetex installs all necessary packages automatically while knitting to PDF, but that doesn't seem to work now.

I actually just got it to work by myself now after installing the xurl LaTeX package manually via tinytex::tlmgr_install("xurl"). Now the article2 template renders perfectly!

Thanks so much for this fix! I was banging my head against this for a while.