From 2c8e61609de68935545d3d736580d14cd0b92747 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Thu, 12 Nov 2026 21:59:39 +0000 Subject: [PATCH 1/2] wolfSSL manual: escape backslashes in API text for the PDF build New Doxygen comments in wolfssl (asn_public.h and ssl.h, for X509_NAME_oneline) contain the text "\xHH". pandoc passes anything that looks like a TeX command through as raw LaTeX, so xelatex stopped with "Undefined control sequence" and the PDF build failed. In pdf-prep, double any backslash followed by a letter in the API reference pages, outside fenced code blocks and inline code, so it is printed literally. This covers the case generally instead of adding another one-off rule like the existing \par one. The HTML build is not affected. --- wolfSSL/Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wolfSSL/Makefile b/wolfSSL/Makefile index 335ef25c..4abd2b3e 100644 --- a/wolfSSL/Makefile +++ b/wolfSSL/Makefile @@ -90,6 +90,10 @@ html-prep: api # 4. Three regexes to remove metadata which outputs in the PDF text # 5. Fix titles of the header files Markdown # 6. Two regexes to handle bad Doxygen that didn't convert and the LaTeX processor thinks is LaTeX commands +# 7. Escape any other backslash followed by a letter in the API text (outside +# code blocks and inline code), for example "\xHH" in a comment. pandoc +# otherwise passes it through as a raw LaTeX command and xelatex fails with +# "Undefined control sequence". # Cat: # A. wolfSSL API Reference # B. wolfCrypt API Reference -> Utilities / basic items, then Algorithms @@ -115,6 +119,7 @@ pdf-prep: api $(Q)perl -i -pe "s/dox_comments\/$(HEADER_FILES)\///" build/pdf/*8h* $(Q)perl -i -pe "s/^\\\\//" build/pdf/group* build/pdf/*8h* $(Q)perl -i -pe "s/\\\\par/par/g" build/pdf/group* build/pdf/*8h* + $(Q)perl -i -pe 'if ($$ARGV ne $$p) { $$f = 0; $$p = $$ARGV } if (/^\s*```/) { $$f = !$$f; next } next if $$f; s{(`+[^`]*`+)|\\(?=[A-Za-z])}{defined $$1 ? $$1 : "\\\\"}ge' build/pdf/group* build/pdf/*8h* $(Q)perl -i -pe "s/group__.*?\.md//g" build/pdf/*8h* build/pdf/chapter* build/pdf/appendix* $(Q)perl -i -pe "s/[A-Za-z0-9_-]+_8h\.md//g" build/pdf/chapter* build/pdf/appendix* $(Q)cat build/pdf/group__CertManager.md build/pdf/group__Memory.md build/pdf/group__openSSL.md build/pdf/group__CertsKeys.md build/pdf/group__IO.md build/pdf/group__Setup.md build/pdf/group__Debug.md build/pdf/group__TLS.md >> build/pdf/appendix01.md From a55059a8324fd706871ce796da305fe79b86498c Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Thu, 12 Nov 2026 22:14:59 +0000 Subject: [PATCH 2/2] wolfSSL manual: make the PDF backslash escape Markdown aware Move the escape step into pdf-escape-backslashes.pl and address review feedback on the inline perl rule: - Keep existing Markdown escapes whole, including an already escaped "\\". The old rule doubled the second backslash of "\\x", leaving a raw "\x" for LaTeX again. - Recognise ~~~ fences as well as ``` and only close a fence with the same character and at least the same length. - Treat inline code spans by delimiter length, including spans that continue onto the next line of a paragraph. None of these cases occur in the current API output, where the only escaped text is still the three "\xHH" occurrences. --- wolfSSL/Makefile | 10 ++--- wolfSSL/pdf-escape-backslashes.pl | 66 +++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 wolfSSL/pdf-escape-backslashes.pl diff --git a/wolfSSL/Makefile b/wolfSSL/Makefile index 4abd2b3e..55365ffd 100644 --- a/wolfSSL/Makefile +++ b/wolfSSL/Makefile @@ -90,10 +90,10 @@ html-prep: api # 4. Three regexes to remove metadata which outputs in the PDF text # 5. Fix titles of the header files Markdown # 6. Two regexes to handle bad Doxygen that didn't convert and the LaTeX processor thinks is LaTeX commands -# 7. Escape any other backslash followed by a letter in the API text (outside -# code blocks and inline code), for example "\xHH" in a comment. pandoc -# otherwise passes it through as a raw LaTeX command and xelatex fails with -# "Undefined control sequence". +# 7. Escape any other backslash followed by a letter in the API text, for +# example "\xHH" in a comment (pdf-escape-backslashes.pl; code and existing +# Markdown escapes are left alone). pandoc otherwise passes it through as a +# raw LaTeX command and xelatex fails with "Undefined control sequence". # Cat: # A. wolfSSL API Reference # B. wolfCrypt API Reference -> Utilities / basic items, then Algorithms @@ -119,7 +119,7 @@ pdf-prep: api $(Q)perl -i -pe "s/dox_comments\/$(HEADER_FILES)\///" build/pdf/*8h* $(Q)perl -i -pe "s/^\\\\//" build/pdf/group* build/pdf/*8h* $(Q)perl -i -pe "s/\\\\par/par/g" build/pdf/group* build/pdf/*8h* - $(Q)perl -i -pe 'if ($$ARGV ne $$p) { $$f = 0; $$p = $$ARGV } if (/^\s*```/) { $$f = !$$f; next } next if $$f; s{(`+[^`]*`+)|\\(?=[A-Za-z])}{defined $$1 ? $$1 : "\\\\"}ge' build/pdf/group* build/pdf/*8h* + $(Q)perl pdf-escape-backslashes.pl build/pdf/group* build/pdf/*8h* $(Q)perl -i -pe "s/group__.*?\.md//g" build/pdf/*8h* build/pdf/chapter* build/pdf/appendix* $(Q)perl -i -pe "s/[A-Za-z0-9_-]+_8h\.md//g" build/pdf/chapter* build/pdf/appendix* $(Q)cat build/pdf/group__CertManager.md build/pdf/group__Memory.md build/pdf/group__openSSL.md build/pdf/group__CertsKeys.md build/pdf/group__IO.md build/pdf/group__Setup.md build/pdf/group__Debug.md build/pdf/group__TLS.md >> build/pdf/appendix01.md diff --git a/wolfSSL/pdf-escape-backslashes.pl b/wolfSSL/pdf-escape-backslashes.pl new file mode 100644 index 00000000..7a60a54a --- /dev/null +++ b/wolfSSL/pdf-escape-backslashes.pl @@ -0,0 +1,66 @@ +#!/usr/bin/env perl +# +# Escape backslashes in the Doxybook2 API reference pages before the PDF +# build. pandoc reads a backslash followed by letters (for example "\xHH" in +# an API comment) as a raw LaTeX command and passes it to xelatex, which then +# fails with "Undefined control sequence". Such a backslash is doubled so that +# pandoc prints it literally. +# +# Left unchanged: +# - fenced code blocks (``` or ~~~, closed by a fence of the same character +# that is at least as long as the opening one) +# - inline code spans, including spans that continue onto the next line +# - existing Markdown escapes, i.e. a backslash followed by anything other +# than a letter (this includes an already escaped "\\") +# +# Usage: perl pdf-escape-backslashes.pl FILE... (files are edited in place) + +use strict; +use warnings; + +sub escape_prose { + my ($text) = @_; + $text =~ s{ + ( # 1: inline code span + (?; + close $in; + + my ($out, $prose, $fence) = ('', '', ''); + for my $line (@lines) { + if ($fence eq '') { + if ($line =~ /^[ \t]*(`{3,}|~{3,})/) { + $out .= escape_prose($prose) . $line; + $prose = ''; + $fence = $1; + } + else { + $prose .= $line; + } + } + else { + $out .= $line; + my $c = substr($fence, 0, 1); + if ($line =~ /^[ \t]*(\Q$c\E{3,})\s*$/ + && length($1) >= length($fence)) { + $fence = ''; + } + } + } + $out .= escape_prose($prose); + + open my $o, '>', $file or die "$file: $!\n"; + print {$o} $out; + close $o or die "$file: $!\n"; +}