Skip to main content

Syntax Highlighting for PDF

Abstract

You can set up syntax highlighting for PDF outputs so that code samples use colors for the syntax.

Use a PDF layout to set up syntax highlighting for PDF:

  1. Select Layout in the top menu.

    Paligo editor. The Layout option in the header menu is highlighted.

    Paligo displays a list of Layouts. The list is empty if there are no custom Layouts in your Paligo instance.

  2. Select the Layout you want to update or Create a Layout.

    Tip

    You can copy the URL of the Layout Editor and paste it into a new tab in your browser. This can be useful if you frequently switch between your Paligo content and the Layout settings.

  3. Select Verbatim (code and software) and choose Syntax Highlight.

    PDF layout editor showing Verbatim (code and software) settings is open, and Syntax Highlight is selected. The main display area shows the Syntax Highlight editing settings.
  4. Use the settings to set up syntax highlighting for your PDF output:

    • Turn syntax highlight on - Set the syntax highlighting feature to Enabled (on) or Disabled (off).

    • Default language when no language attribute has been set - If the code samples in your topics do not have a language set, Paligo will usually be able to identify the language automatically. But if it cannot identify the language, it will assume the code sample is in the default language. Use this setting to define the default language.

    • Default style for syntax highlight - Choose a theme. Each theme provides a different color scheme for syntax highlighting and may highlight different parts of the code. We recommend that you experiment until you find the theme that best meets your requirements.

    Note

    The default language and default style are only used if a code sample does not have its own attributes set for language and style.

  5. Select Save.

  6. You can use the language attribute to give a code sample its own language and style settings that will be used instead of the defaults. This is useful if Paligo is unable to recognize the language automatically.

    1. Edit the topic that contains the code sample and select the verbatim element for the sample, for example, the programlisting element.

    2. In the Element Attributes Panel, add the language attribute and enter a supported language as the value. For example, javascript. To find out what values you can use, see Syntax Highlighting Languages for PDF.

      language-javascript.jpg
    3. Add the role attribute and enter a supported theme name as the value. For example, role: fruity. This is an optional step. Typically, you would want all code samples to use the same theme for consistency, and so would set a default theme on the layout and not use the role attribute on individual code samples.

      role-fruity.jpg

      Note

      You can set the value to any theme that is listed in the Default style for syntax highlight setting on the PDF layout editor.

  7. Select Save. Save icon.

When you publish to PDF using the layout you edited, the PDF output will use syntax highlighting. If a code sample has its own language and role set, Paligo will apply those. If a code sample does not have its own language and role set, Paligo will attempt to identify the language automatically and will use the default theme. If Paligo cannot identify the language automatically, it will use the default language that is set in the layout.