rnuske / komaletter

R package for comfortable writing of beautiful PDF letters in Markdown.
https://rnuske.github.io/komaletter
86 stars 21 forks source link

Adding letterhead/logo on top of letter #16

Open michielvandijk opened 2 years ago

michielvandijk commented 2 years ago

I would like to add the university logo to the top of the letter so it more-or-less replicates the standard template. I followed the approach as described here:

https://stackoverflow.com/questions/27982052/insert-a-logo-in-upper-right-corner-of-r-markdown-pdf-document

And added this in the yaml: header-includes:

plus a header.tex with the following information in the same folder

\usepackage{fancyhdr} \pagestyle{fancy} \rhead{\includegraphics[width = .05\textwidth]{logo.png}}

Nothing, however, seems to happen. I suppose the header-includes is not supported (yet) by the package. Not sure if this is easy to implement but this seems to be a general feature that users would like to use.

rnuske commented 2 years ago

you are right, that approach does not work here.

The layout of the letter is defined in a letter class option file (lco). The default lco is just a layout that I like. You could use one of the standard layouts of the underlying latex class scrlttr2 (cf. vignette letter_example_2 web version). Some of those lco's are listed in vignette 'introduction to komaletter' web. Or define your own lco for instance based on the packages' default lco see vignette letter_example_1 web. You wouldn't need to do the 'system.file()'-thing just put your lco in the same directory and merely specify the filename of the lco.

Having said the above, I gotta say I'm still undecided on adding an option to replace the author name with an image file/logo in the upper right hand corner.

salim-b commented 2 years ago

A few remarks and corrections:

Hope that helps.

rnuske commented 2 years ago

Hi @salim-b

thank you for your input. I am not quite sure which part of your writing addresses me. Are you suggesting any changes in the package?

As you write, the inclusion of additional Tex is possible via the YAML tags provided by rmarkdown, on top of which komaletter is built. The inclusion of header-includes in the komaletter template is identical to pandoc's default-latex template. Does this part need to be changed?

salim-b commented 2 years ago

Hi @rnuske

I am not quite sure which part of your writing addresses me.

I wasn't really addressing you but rather the OP and future readers of this issue in general (while I was looking for a solution to include a logo in a letter created with komaletter I stumpled upon this issue and thought it would be nice to share my findings).

The inclusion of header-includes in the komaletter template is identical to pandoc's default-latex template. Does this part need to be changed?

You're right. I somehow assumed komaletter's template would ignore the header-includes variable since one of my early experiments relying on it failed. But it's clearly there (and works). I've update my post above accordingly. Sorry for the confusion.

Are you suggesting any changes in the package?

Not really. I think the KOMA-Script LaTeX letter class scrlttr2 already contains configuration variables in excess. Adding even more config options (for logo inclusion or whatever) beyond what scrlttr2 supports seems overkill to me.

One thing though that bothers me about komaletter's template is that the LaTeX package graphicx is only loaded when one of the template variables graphics or signature is set:

https://github.com/rnuske/komaletter/blob/51f388844ef6789323b6e04c494bf62bffe3fd3a/inst/rmarkdown/templates/pdf/resources/template.tex#L165-L166

https://github.com/rnuske/komaletter/blob/51f388844ef6789323b6e04c494bf62bffe3fd3a/inst/rmarkdown/templates/pdf/resources/template.tex#L235-L236

This means that a simple \includegraphics{} call will by default produce an error message during build. This is consistent with Pandoc's default template. But while Pandoc targets a wide range of input/output formats, komaletter is intended to be used for LaTeX/PDF output only. So maybe we could change the template to load graphicx unconditionally?

Furthermore, in an ideal world, komaletter's documentation would be extended to include

Anyways, thanks a lot for developing and maintaining this package!