Contents | Start | End | Previous: KB0166: How can I move the table of contents from the start of the book? | Next: KB0168: How can I get a word count?


KB0167: Can Jutoh format computer source code?

From version 2.36, Jutoh can help format source code excerpts, using the command Format | Insert | Code (Shift+Alt+J), or code formatting in the Objects window. You can refer to the description of the Code formatter dialog in the Jutoh manual.

If you wish to do it manually, you can create four paragraph styles, for example Code, Code First Line, Code Last Line, and Code Single Line. Set the paragraph spacing appropriately in these styles, and apply the styles to your code. This allows you to achieve the correct spacing between lines of source code, a fixed-space font, and so on.

To ensure spaces are respected in the book, for example for indenting lines, insert non-breaking spaces via Format | Insert | Symbol | Non-Breaking Space.

If the built-in syntax highlighting in the Code Formatter is insufficient, you could try using OpenOffice/LibreOffice, and then copying and pasting it into Jutoh. You can search for LibreOffice extensions to help you; one such extension is Code Colorizer Formatter.

By default, Jutoh doesn't export face names so fixed-width fonts won't be used initially; you can fix this by using the Styles with font names configuration option to selectively output face names for certain paragraph styles. Or, use Styles with generic font names to output the generic font family 'monospace' without specifying a specific font.

You could check Generate font names and Generate generic font names to specify fonts for all styles, but on some devices this will disable the ability to choose fonts for the majority of the book's text.


Contents | Start | End | Previous: KB0166: How can I move the table of contents from the start of the book? | Next: KB0168: How can I get a word count?