Search code examples
javamarkdownjavadocpandoc

A Javadoc comment with accented characters mixes blue and black color in its text on a Pandoc generated pdf. One without accented characters doesn't


Why do I have mixed colors in Javadoc comments when using accented characters?

This markdown:

/** Première manière **/
@GetMapping
public String index() {
   return "Hello Spring Boot";
}
   
/** Deuxième manière */
@RequestMapping("/")
public String greetings() {
   return "Greetings";
}

produces this on a pdf, with Pandoc:

enter image description here

Blue and black colors are mixed in the middle of the text comment. Each time it encounters an accented character, here: è.

But without accented characters, it produces that:

enter image description here

Here, it's more correct, but I wonder why the whole Javadoc comment isn't blue?

my header-includes are these ones, but I have the same behavior whatever:

  • I put some one header-includes or not,
  • the Java code is under a citation or not,
  • in a box,
  • in a group
header-includes:
- \usepackage{tcolorbox}
- \usepackage{fvextra}
- \DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,breakanywhere,breaksymbol=,breakanywheresymbolpre=,commandchars=\\\{\}}

Is there a way to correct the behavior with accented characters? It doesn't have a nice effect.


@abra If I change è with è, é with é and all the characters here it produces this:

enter image description here


Solution

  • The issue is not specific to PDF, it also happens when converting to HTML:

    pandoc -s test.md -o test.html
    

    For syntax highlighting, pandoc uses KDE XML syntax definition files. The one for Java is here.

    Download it and open it in a text editor. You will find this at line 3777:

    <!-- Comment next line if you don't use Javadoc tool -->
    <IncludeRules context="##Javadoc"/>
    

    Do as indicated in the comment:

    <!-- Comment next line if you don't use Javadoc tool -->
    <!--IncludeRules context="##Javadoc"/-->
    

    Now convert with your custom syntax definition file:

    pandoc --syntax-definition=java.xml -s test.md -o test.html
    

    Here is the result:

    enter image description here