I'm trying to recreate markdown-style inline code blocks in latex, you know, these things. They should have a slightly highlighted background, but not influence line height or word separation of the text they are defined in. Also, blocks with tall content like | should have the same height as others like -.
This is my attempt recreating them in latex:
\documentclass[a4paper, 12pt, hidelinks]{report}
\usepackage{tcolorbox}
\newcommand{\code}[1]{\mbox{
\ttfamily
\tcbox[
on line,
boxsep=0pt, left=4pt, right=4pt, top=2pt, bottom=1.5pt,
toprule=0pt, rightrule=0pt, bottomrule=0pt, leftrule=0pt,
oversize=0pt, enlarge left by=0pt, enlarge right by=0pt,
colframe=white, colback=black!12
]{#1}
}}
\begin{document}
This is a \code{test} for markdown-style \code{code blocks}.
Plus \code{+} Minus \code{-}
\end{document}
Unfortunately, this attempt creates extensive word spacing, unwanted space before punctuation, and doesn't have uniform height:
Can someone tell me how to improve these code blocks?
EDIT: The unwanted space can be removed by adding % to the end of some lines in the macro. Thanks to @Teepeemm for suggesting this fix in the comments.



%to the end of some of your lines. See https://tex.stackexchange.com/q/7453/107497 – Teepeemm Oct 17 '22 at 13:45