I know that this has been discussed before (in particular here: https://forums.madcapsoftware.com/viewtopic.php?f=6&t=8630) but I haven't found a solution anywhere for PDF output in particular.
A few notes:
- My experimentation shows that the lines of text will happily extend outside of the <pre> and <body> tags no matter how I try to control them. Really long lines may break eventually, but generally only if they have spaces in them, and often after they have extended off the page.
- PDF output happily ignores a lot of the standard tools for fixing line break issues in CSS: overflow: auto; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; word-break: break-word.
- Madcap Hyphenation rules are not particularly useful because I don't want hyphens in the code. Spaces would be fine, actually.
- The only thing I've had any luck with is controlling the width of the pre block. If I set a fixed width, the text will actually break to the next line when it gets to the maximum width.
- However - here's the weird thing. The pre tag seems to start calculating its width starting after any tab characters for the purposes of line length. I would need to set the maximum width small enough that code on e.g. the fourth level of tabs does not extend off the page, but that leads to unnecessary line breaks on the 1st-3rd levels.
- This weird behaviour applies when tabs are used to produce the white space, but it seems to act as expected (honouring the actual width of the block) when spaces are used.
Possible Solution: Use different style classes with different width definitions for each level of code. A pain because of how much code I have imported from another system, but not inherently impossible. It's really the only reasonable solution I can think of.
But before I implement that: has anyone else come up with a solution to this in the decade since the last forum discussion about it?