Wandmalfarbe / pandoc-latex-template

A pandoc LaTeX template to convert markdown files to PDF or LaTeX.
BSD 3-Clause "New" or "Revised" License
6.22k stars 968 forks source link

Inline code segments hard to distinguish from regular text #183

Closed sylencecc closed 4 years ago

sylencecc commented 4 years ago

Rendering of inline code blocks surrounded by backticks is weird, see attached example. Letters are colored, while numbers and special characters are black, just as the rest of the text. The code is properly set in a monospaced font, but still hard to distinguish from surrounding text. Would it be possible to adopt the way GitHub renders inline code, that is by changing the background of those segments to some greyish color, maybe the one you already use for listings (such as this)?

Apart from that, the bold highlighting of for may be due to the renderer assuming some sort of default language the snippet is written in? Is it possible to have no default there, so that at least the whole code block uses the blue font color?

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do `\/etc\/.*\/something` eiusmod tempor incididunt 
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut 
`Bits 12-23 of /proc/0/pagemap entries are about to stop being page-shift some time soon. See the 
linux/Documentation/vm/pagemap.txt for details` aliquip ex ea commodo consequat. Duis aute irure dolor in 
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat 
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

pandoc

cagix commented 4 years ago

Probably only suitable definitions are missing here that extend the verbatim environment ...

In the meantime, a filter like

function Code(el)
    return { pandoc.RawInline("latex", "\\inlinecode{"), el, pandoc.RawInline("latex", "}") }
end

could help plus something like this definition

\usepackage{tcolorbox}
\newtcolorbox{codeblock}{enhanced,frame hidden,colback=code,borderline={1pt}{1pt}{border,dotted}}

(to be included via -H)

Wandmalfarbe commented 4 years ago

Rendering of inline code blocks surrounded by backticks is weird, see attached example. Letters are colored, while numbers and special characters are black, just as the rest of the text.

Yes, this is the desired coloring for code. The language is assumed to be Java when no language is selected (e.g. for inline code).

The code is properly set in a monospaced font, but still hard to distinguish from surrounding text.

That's true. Maybe you want to use the built-in highlighting that pandoc provides via skylighting. Please see the section Syntax Highlighting Without Listings in the readme and the Pandoc manual on the topic. As far as I know the pandoc syntax highlighting is only applied to fenced code blocks.

Would it be possible to adopt the way GitHub renders inline code, that is by changing the background of those segments to some greyish color, maybe the one you already use for listings (such as this)?

There was already an issue reported on that topic here: https://github.com/Wandmalfarbe/pandoc-latex-template/issues/42. listings has no way to add a background color to inline code and I'm not convinced of the other solutions mentioned in that thread.

Apart from that, the bold highlighting of for may be due to the renderer assuming some sort of default language the snippet is written in? Is it possible to have no default there, so that at least the whole code block uses the blue font color?

Yes, the default language is Java. My reasoning was that you get good enough highlighting even when no syntax is specified. I deliberately choose this because adding a language attribute on every inline code block is very tedious.

Pandoc does support this via the extension inline_code_attributes:

Extension: inline_code_attributes

Attributes can be attached to verbatim text, just as with fenced code blocks:

`<$>`{.haskell}

I might consider an option to change the default language (Issue https://github.com/Wandmalfarbe/pandoc-latex-template/issues/192). That would only work for listings and needs some thought.

In the meantime you can attach a language attribute with the value txt to your code to disable the Java highlighting like so:

This is some text. `This is code for my document`{.txt} This is some text
cagix commented 4 years ago

@Wandmalfarbe I've got the impression the OP was mainly bothered by the fact that inline code does not use a background color like in rendering on Github. Would it be helpful to include a reference to the wrapping in a tcolorbox (or other) like proposed in https://github.com/Wandmalfarbe/pandoc-latex-template/issues/183#issuecomment-682390772 in the Readme.md? This way a coloured background is generated for inline code, and no changes to the template are necessary.