Problem
Remaining \texttt{} macros in markdown output, primarily in math contexts. Analysis shows:
- n4950: 23 instances
- trunk: 39 instances
- Total: 62 instances
Root Cause
\tcode{} macros preserved in math mode by Pandoc, appearing as \texttt{} in output.
Solution
Extended cpp-math.lua to handle display math contexts:
-
Display Math Handler: Added elseif elem.mathtype == "DisplayMath" branch
- Converts
\tcode{}/\texttt{} to backticks before Unicode conversion
- Applies preprocessing (strips
\placeholder{}, \ensuremath{}, text macros)
- Uses all-or-nothing approach: fully convert to Unicode or revert to preprocessed LaTeX
-
Test Coverage: Added 4 new tests in test_math.py:
test_texttt_in_display_math() - Basic display math blocks
test_tcode_in_display_math() - XOR operator handling
test_multiple_texttt_in_display_math() - Multiple macros
test_texttt_in_complex_display_math() - Multi-line \begin{align*}
Results
- n4950: 23 → 14 instances (39% reduction, 9 fixed)
- Test suite: 483 → 487 tests, all passing
Remaining Edge Cases (14 instances)
- Nested
\texttt{\textit{}} (containers.md)
- Escaped special chars
\texttt{\} (lex.md)
- Complex inline math (ranges.md)
- Escaped underscores (utilities.md)
These harder edge cases require more sophisticated handling and can be addressed in future work.
Files Changed
src/cpp_std_converter/filters/cpp-math.lua - Display math handling
tests/test_filters/test_math.py - 4 new tests
Problem
Remaining
\texttt{}macros in markdown output, primarily in math contexts. Analysis shows:Root Cause
\tcode{}macros preserved in math mode by Pandoc, appearing as\texttt{}in output.Solution
Extended
cpp-math.luato handle display math contexts:Display Math Handler: Added
elseif elem.mathtype == "DisplayMath"branch\tcode{}/\texttt{}to backticks before Unicode conversion\placeholder{},\ensuremath{}, text macros)Test Coverage: Added 4 new tests in
test_math.py:test_texttt_in_display_math()- Basic display math blockstest_tcode_in_display_math()- XOR operator handlingtest_multiple_texttt_in_display_math()- Multiple macrostest_texttt_in_complex_display_math()- Multi-line\begin{align*}Results
Remaining Edge Cases (14 instances)
\texttt{\textit{}}(containers.md)\texttt{\}(lex.md)These harder edge cases require more sophisticated handling and can be addressed in future work.
Files Changed
src/cpp_std_converter/filters/cpp-math.lua- Display math handlingtests/test_filters/test_math.py- 4 new tests