pandoc-emphasize-code icon indicating copy to clipboard operation
pandoc-emphasize-code copied to clipboard

CodeEmphasisLine called on every word in a line instead of the whole line

Open coreyhuinker opened this issue 6 years ago • 4 comments
trafficstars

Here is my input file, example.md, only a slight variation on doc example from the docs:

---
header-includes:
  - \usepackage{listings}
  - \lstset{basicstyle=\ttfamily}
  - \newcommand{\CodeEmphasis}[1]{\textcolor{red}{\textit{#1}}}
  - \newcommand{\CodeEmphasisLine}[1]{\colorbox{yellow}{#1}}
---

# My Slide {.fragile}

```{.haskell emphasize=2:3-2:14,3:3-3:12,4-4}
myFunc = do
  one two three
  four five six
  seven eight nine
  ten eleven twelve
```

When I run pandoc --filter pandoc-emphasize-code --to beamer example.md --output example.pdf

Instead of one solid yellow background I get irregularly shaped backgrounds around each word.

When I run pandoc --filter pandoc-emphasize-code --to beamer example.md

I get the following output:

\begin{frame}[fragile]{My Slide}
\protect\hypertarget{my-slide}{}

\begin{lstlisting}[escapechar=£,language=haskell]
myFunc = do
  £\CodeEmphasis{one}£ £\CodeEmphasis{two}£ £\CodeEmphasis{thre}£e
  £\CodeEmphasis{four}£ £\CodeEmphasis{five}£ six
  £\CodeEmphasisLine{seven}£ £\CodeEmphasisLine{eight}£ £\CodeEmphasisLine{nine}£
  ten eleven twelve
\end{lstlisting}

\end{frame}

and you can see \CodeEmphasisLine is wrapped around each word in the line, rather than the line itself. This has no consequences the styling is purely on the text (i.e. \textit), but when the styling involves the background color it leads to a PDF with a series of blocks around each word, with white/background-space in between the highlighted words.

coreyhuinker avatar May 03 '19 16:05 coreyhuinker

Hi, thanks for reporting! It does indeed look like a bug. I believe the line emphasis feature was added after the LaTeX output, and it might have been an oversight.

Would you like to submit a PR to fix this? I can look at it otherwise, but might not have time at least in the coming week(s).

owickstrom avatar May 05 '19 15:05 owickstrom

I also recall that the reason the LaTeX emphasizer splits on each word and wraps non-spaces is because of the complexity of includes spaces within the emphasis wrappers. It might have just been my lack of understanding of LaTeX, and something that's solvable if you just know how to. :smile:

owickstrom avatar May 05 '19 15:05 owickstrom

At the moment, I know relatively little about LaTeX and even less about Haskell. It's an interesting problem that may inspire me to learn more about both, but my timeline for that is similar to yours.

coreyhuinker avatar May 05 '19 16:05 coreyhuinker

Gotcha. If anyone else comes along and wants to take a stab it this I'm happy to discuss the design.

owickstrom avatar May 12 '19 14:05 owickstrom