rstudio / rticles

LaTeX Journal Article Templates for R Markdown
https://pkgs.rstudio.com/rticles/
1.47k stars 519 forks source link

PDF bookmarks not shown #334

Closed nurfatimaj closed 3 years ago

nurfatimaj commented 4 years ago

Hi!

I am trying to incorporate the AEA template into my bookdown setup. So far, I have copied the template, AEA.cls and two accompanying .sty files into my project folder. Everything seems to be working except the resulting pdf file does not have bookmarks for sections anymore.

If I understand correctly the bookmarks have to be taken care of by hyperref package. This is how I introduce the hyperref package into my templates.

\usepackage[colorlinks, 
            allcolors = blue, 
            linktoc = true, 
            bookmarks = true, 
            bookmarksopen = true, 
            pdfpagelabels]{hyperref}

When I use my old template with exactly the same options of hyperref, the pdf has the bookmarks for sections. But as soon as I change the template to aea, they disappear.

If you could help me out with this, I'd be grateful! I am clueless even where to begin looking for mistakes.

cderv commented 4 years ago

I am trying to incorporate the AEA template into my bookdown setup. So far, I have copied the template, AEA.cls and two accompanying .sty files into my project folder. Everything seems to be working except the resulting pdf file does not have bookmarks for sections anymore.

What are you trying to do exactly ?

Do you want bookdown features for your AEA article ? If so, did you see and try the base_format argument ? https://bookdown.org/yihui/bookdown/a-single-document.html

Otherwise, can you give me more details on what this incorporation looks like ?

Thank you

nurfatimaj commented 4 years ago

Ok, so maybe it helps to give a bit of a back story. I have only started writing my thesis using bookdown this May. I have actually started from oxforddown, but adapted its template to my needs. Basically adding some more packages, removing the unnecessary images and so on.

It was working well. Recently I found out about rticles package and I thought that it would be nicer to be maybe working with these templates. Especially, since it contains the official template for AEA.

It might also help to know that in my field a thesis is basically a collection of articles. Therefore, the document I have right now is a single article with separate Rmd files for separate sections. So, in my understanding I am using the bookdown structure to create a single article.

To transition to the AEA template, I tried to copy all the necessary things I saw in Github repository under aea_template folder.

Maybe it is more clear if I show how my index.Rmd and aea_template.tex files look like.

index.Rmd

title: Title
short: Short title
journal: "AER" # AER, AEJ, PP, JEL
month: "" # "`r format(Sys.Date(), '%m')`"
year: "" # "`r format(Sys.Date(), '%Y')`"
vol: 
issue: 
author:
  - name: Nurfatima Jandarova
acknowledgements: 
abstract: |
  `r paste(readLines("_abstract.Rmd"), collapse = '\n ')`

draft: TRUE

# ... Other arguments for biblatex ...

output:
  bookdown::pdf_book:
    base_format: rticles::aea_article
    template: templates/aea_template.tex
    latex_engine: pdflatex
    keep_tex: true
    citation_package: biblatex 
    pandoc_args: --top-level-division=section 

aea_template.tex

\documentclass[$journal$, $if(draft)$draftmode$endif$]{templates/AEA}
\usepackage[colorlinks, 
            allcolors = blue, 
            linktoc = true, 
            bookmarks = true, 
            bookmarksopen = true, 
            pdfpagelabels]{hyperref}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{color}
\usepackage{biblatex}

\addbibresource{$bibliography$}

%%%%% DOCUMENT TITLE PAGE INFORMATION
\title{$title$}
$if(short)$\shortTitle{$short$}$endif$

\author{
$for(author)$
  $author.name$$sep$\\
$endfor$
\thanks{
$for(author)$
  $author.surname$: $author.affiliation$, $author.email$.
$endfor$
$if(acknowledgements)$
  $acknowledgements$
$endif$
}}

\date{\today}
\pubMonth{$month$}
\pubYear{$year$}
\pubVolume{$vol$}
\pubIssue{$issue$}
\JEL{$for(jel)$$jel$$sep$, $endfor$}
\Keywords{$for(keywords)$$keywords$$sep$, $endfor$}

\draftSpacing{1.5}

\begin{document}

%%%%% ABSTRACT -- Nothing to do here except comment out if you don't want it.
\begin{abstract}
$abstract$
\end{abstract}

% Title page is created here
\maketitle

% all your chapters and appendices will appear here
$body$

\end{document}

I added the base_format option after your message above. It did not seem to have changed anything. Maybe because I have already duplicated the work by having aea_template.tex file.

My old template was basically the same as one above, except it used \documentclass{article}. Given that they are almost identical, I don't understand why one creates bookmarks in the pdf and the other doesn't.

nurfatimaj commented 3 years ago

Just in case someone might have a clue or something.

I have made this dummy file

\documentclass{AEA}

\usepackage{hyperref}

\begin{document}
    Hello
    \section{Section 1}
    \subsection{Subsection 1}
    \section{Section 2}
\end{document}

which doesn't show table of contents when I open pdf in pdf reader.

image

After I delete all files except the .tex and change it to

\documentclass{article}

\usepackage{hyperref}

\begin{document}
    Hello
    \section{Section 1}
    \subsection{Subsection 1}
    \section{Section 2}
\end{document}

the generated pdf file shows table of contents in the pdf reader.

image

If I don't clean up all auxiliary files, then even after I change document class to article, there is no table of contents in the pdf reader.

So I guess this means that somehow the AEA class does not allow for pdf bookmarks. Or that I need some other file in addition to AEA.cls for the bookmarks to work properly?

If anyone could have a look at this, I'd be very very grateful. I tried to go through the AEA.cls file, but I don't really understand it very well. I can't find any place that could have forbidden pdf bookmarks.

Thank you!

cderv commented 3 years ago

Hi @nurfatimaj,

Sorry I did not have time to look at this earlier. I see you are closing. Did you find your solution ? Is there something to improve in the template ?

nurfatimaj commented 3 years ago

Ah, yes, sorry. I forgot to leave the message here.

So, I also asked for advice from hyperref package. They replied that the reason is because the class doesn't use table of contents, which makes tocdepth to zero. They also suggested a solution that worked for me: load hyperref package with bookmarksdepth option:

\usepackage[bookmarksdepth = 3]{hyperref}

But since I do not really know class files, I don't know if there is anything to fix in the class file itself. I don't know if forcing a class to have a non-zero tocdepth, would conflict with something else in the class file. 🤷🏽‍♀️

I hope this helps.

Thank you!

cderv commented 3 years ago

Thanks for sharing!

The template use hyperref https://github.com/rstudio/rticles/blob/1127655f47cff67276bbf85a0fe73bbeb4a36c13/inst/rmarkdown/templates/aea/resources/template.tex#L26

We could modify the template to

Are you copying and modifying the template currently for AEA ?

nurfatimaj commented 3 years ago

I'm sorry, I am not sure I understand your question entirely. I did not use the template file from rticles package, because I only learned about relatively recently. I have my own template, where I set document class to AEA. I copied the .cls and .sty files from rticles package to my templates folder, for the document class to work. So, in my own template, I added the bookmarksdepth option to the hyperref package. At some point I think I will switch to the template from this package, once I understand how can I load the packages from within index.Rmd file. I just started getting the header-includes option. Right now I have all of the packages hard-coded into template file.

cderv commented 3 years ago

Oh thank you for the precision ! I wasn't aware of this usage of rticles 😄 So yes we would need to modify the template in rticles and the mechanism so that you would be able to do the same.

At some point I think I will switch to the template from this package, once I understand how can I load the packages from within index.Rmd file

You can find info here: https://bookdown.org/yihui/rmarkdown/rticles-usage.html

Thank you for the report on this!

nurfatimaj commented 3 years ago

Thanks a lot!

github-actions[bot] commented 3 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.