rnuske / komaletter

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

sections/subsections inside the letter #13

Closed bnicenboim closed 1 year ago

bnicenboim commented 3 years ago

Hi This looks great! I was wondering if there is a way (or a hack) to add subsections inside the letter.

rnuske commented 3 years ago

An interesting idea. I never before tried to create sections in a letter. The naive way # section one does not work

! Undefined control sequence.
<argument> \section 
                    {section one}\label {section-one}
l.95 \section{section one}\label{section-one}}

I will research where that error occurs and report back.

rnuske commented 3 years ago

It seems to be more complicated. This package employs the KOMA-Script class scrlttr2, which does not support sections. There was a "hack" to add sections after the fact (by the author of KOMA-Script), which is now deprecated.The way recommended now is to combine KOMA-Script classes such als scrartl with the package scrletter (example).

Switching to scrletter would cause a major overhaul of the plumbing of komaletter. So, not my favorite solution. For now I will have a look at the old hack and see if I can use some of its parts.

Just to better understand your use case, are you trying to write legal letters such as this KOMA-Script dummy example?

bnicenboim commented 3 years ago

Hi, not for a legal letter, but for an academic letter of motivation. I just wanted to divide the information in sections. For now, I did it with \vspace{.5cm} Section \vspace{.5cm} But it's not the nicest approach, and sometimes spacing goes crazy.

rnuske commented 3 years ago

Hi Bruno, I couldn't resist and added sections to the default letter layout loosely following Markus Kohm's hack. I reduced the before and after section title vertical space to something more letter friendly.

Please test my changes in branch sections and let me know what you think about the implementation and the spacing. This is a first experiment and I'm open to adjustments and better ideas ;-)

remotes::install_github("rnuske/komaletter", ref="sections")



Here some samples:

bnicenboim commented 3 years ago

That's great! I'll check it soon!

bnicenboim commented 3 years ago

Nope, it didn't work:

---
author: Bruno Nicenboim 
return-address: 
  - xxxx
  - xxx
address:
  - xxxx

subject: 
opening: Dear 
closing: Best regards,
signature: Dr. Bruno Nicenboim

lco: NF
output: komaletter::komaletter
---

text text text
## Section

blah blah
rnuske commented 3 years ago

ahh, you built your own lco. The changes are in the komaletter default lco and thus only kick in if you do not specify a custom lco. Have a look at the changed default lco and copy the last part starting with "% Hack to provide sections -------" to your lco then you should have sections in your lco as well.

Please let me know if this works.

It would be gorgeous if you could test the branch without your lco, just to check whether the changes work as intended on a different machine.

bnicenboim commented 3 years ago

ha, I just uninstalled R because I keep having "segfault/core dump" errors (unrelated to this package, of course). So it'll take me some time.

BTW, I didn't built the lco, I used one of the ones that come with komaletter

rnuske commented 3 years ago

ups, I didn't spot that the lco you used is the standard french letter layout. NF is provided by KOMA-Script. On my computer (Ubuntu Linux 20.04) it is under /usr/share/texlive/texmf-dist/tex/latex/koma-script/NF.lco. NF doesn't either have the sections. So, I copied NF.lco renamed it to NF.w.sections.lco (underscores get mangeled by pandoc/LaTeX) in my working directory and added the sections-hack. See attached files (remove txt extension, it's only to get the files into github)



puh, I guess I will start working on the switch to "scrartl + scrletter" sooner rather than later

rnuske commented 3 years ago

@bnicenboim I would like to merge the branch to master.

Were you able to test the default-lco with sections or the NF.w.sections.lco? Do you approve of the vertical spacing around the sections?

Thanks Robert

bnicenboim commented 3 years ago

I copied this file "NF.w.sections.lco" and it didn't work. (I got an error when I tried to knit the doc.) Should I overwrite the original file?

rnuske commented 3 years ago

You do not need to overwrite the original NF.lco.

The easiest case is NF.w.sections.lco and BrunosTest.Rmd in the same directory. BrunosTest.Rmd should than knit without problems. At least it works for me in RStudio with the the CRAN version and section-Branch of the Github version.

bnicenboim commented 3 years ago

Yes, it worked! Sorry for the delay. I would prefer to have a little bit more space below the section, but besides that it looks great. Even the numbering works.

(It doesn't distinguish between #,##, and ###, but I guess it's fine like that).

And notice that it doesn't accept paragraphs ####.

rnuske commented 3 years ago

good to know, thanks for testing.

I followed the example of Markus Kohm and chose \normalsize\bfseries\sffamily for the sections. So all section level have the same styling. The only difference is the amount of space before and after the sections (see test_sections.pdf).

Would you like to have the fourth level of sectioning? I thought maybe three level would be enough in a letter. If the pargraph is needed I could add it, maybe just \normalsize\sffamily without making it bold.

Would you like more space after section, subsection and subsubsection or only after subsubsection?

bnicenboim commented 3 years ago

I think the spacing looks fine in your example.

And adding the paragraph is a good idea.