inbo / INBOmd

An R package with a collection of RMarkdown styles and templates. Elaborate examples are available at https://github.com/inbo/INBOmd_examples
https://inbo.github.io/INBOmd
GNU General Public License v3.0
11 stars 3 forks source link

inbo_rapport: lines having a URL or a hyphen-word tend to be too wide #74

Closed florisvdh closed 3 years ago

florisvdh commented 3 years ago

After compiling bookdown project https://github.com/inbo/osd/tree/624f2fe/src using INBOmd at 595845a (currently on branch 0.4.10), lines with a URL tend to be too wide. We see this e.g. in the references section with one case even running off the page (with several characters effectively invisible):

afbeelding

In the above extract, following references are affected: Departement EWI (2020b), Lowndes (2018), Statistiek Vlaanderen (2020), Statistiek Vlaanderen (s.d.). The Lowndes (2018) reference is an extreme case which was amended in the intermediate TeX file by inserting a line break.

It is also seen in other places, e.g.:

afbeelding

Without URL, it also occurs, perhaps caused by the presence of a hyphen-word:

afbeelding

afbeelding

Also seen in below appendix title, in its intended form, i.e. with hyphen between 'INBO' and 'medewerkers' (not published - see https://github.com/inbo/osd/tree/bbaf912/src):

afbeelding

Better would have been to get 'medewerkers' on new line entirely.

Same for below case (without hyphen-words), i.e. the published version, where title is still a bit too wide even after splitting 'medewerkers' (here too, better would be to not split 'medewerkers' but put it on a newline):

afbeelding

ThierryO commented 3 years ago

The problem with the long url is that the normal hyphenation rules don't provide potential locations to place a hyphen, as the key does not resemble a word. You could try to use the hyphentation key in the yaml header. That accepts a comma separated list of words with hyphen at all the locations where it can break. E.g. me-de-wer-kers would be a very liberal pattern while medewerkers would not allow any hyphenation.

When you place a hyphen, LaTeX considers by default only that location to break the word. Breaking after INBO and placeing medewerkers on a new line would lead to whitespace at the end of the line. The penalty for that whitespace was in this case larger than the penalty for a longer line. Hence no split.

florisvdh commented 3 years ago

Thanks for pointing to a workaround with a YAML key! Still, needing a workaround to make text match 'what it should be like' is not ideal when pursuing wide adoption: it either places a burden on the user, or it leads to unsatisfactory end results. IMHO I think this should be further perfectioned to get the needed behaviour out of the box - if possible. Otherwise people will complain (or worse: abandon), and understandably so.

My estimation of people's perception/taste is that lines sticking out of the usual text margin should be given a very high penalty - it is virtually unacceptable. If feasible, trailing whitespace is then filled by stretching the text within acceptable limits (i.e. not m a k i n g it look ugly), and otherwise a trailing whitespace is still better than exceeding text margin. Clearly, hyphenation is a great help in achieving all this. But also in the case of hyphen-words those conditions should still be fulfilled. That is just my opinion, but I guess that of most people.

In the case of URLs, only pre-existing hyphens can be used, since no hyphens can (nor should) be added in a URL. So there it will happen more often that a trailing whitespace will need to be allowed (with URL starting on a newline), in order not to exceed margins.

All this, of course, also depends on how far you want to go in supporting and perfectioning PDF. But I guess we cannot currently afford to abandon PDF, if ever.

ThierryO commented 3 years ago

Have a look at https://www.texfaq.org/FAQ-nohyph. There is a LaTeX solution to break words with hyphens. But that solution doesn't work with plain markdown syntax.

I'm reluctant to tweak the penalties. If will be hard to get them to work better in all circumstances.

ThierryO commented 3 years ago

I've added a section on this topic to https://github.com/inbo/inbomd_examples/commit/17569cdd497dce1b43287db58427cc77d5987ee3

florisvdh commented 3 years ago

Thanks for the feedback @ThierryO. Good idea to incorporate examples in inbo_rapport. You could share the compiled result with a wider audience to get more opinions on the long-lines subject, than mine alone.