# How do I globally add a border to all inline code that uses /lstinline?

I am using R Markdown and Latex with memoir to compile a book to pdf. I am using lstsetfor the normal code blocks while the inline code is converter and uses \lstinline. I would like to globally add a border (like the one in the photo) around all inline code without affecting the normal code examples.

EDIT: MWE

\documentclass{article}
\usepackage{listings}
\usepackage[framemethod=tikz]{mdframed}

\lstset{
extendedchars=true,
showspaces=false,
xleftmargin=5pt,
framexleftmargin=17pt,
framexbottommargin=0pt,
showtabs=false,
}

\surroundwithmdframed[
innerleftmargin=0pt,
innerrightmargin=0pt,
innertopmargin=5pt,
innerbottommargin=0pt,
linewidth= 0.8pt,
linecolor= gray,
roundcorner=0pt
]{lstlisting}

\begin{document}

This is an example of some inline code that appears like \lstinline{Env.linen} and another one like \lstinline{Out.ar}.  And this is a normal code block:

\begin{lstlisting}
(
SynthDef(\mySynth4, {
var signal, env; // declare variables
env = Env.linen(
attackTime: 0.05,
sustainTime: 0.5,
releaseTime: 1);
signal =
LFCub.ar(freq: 220, mul: 0.3) *
EnvGen.kr(envelope: env, doneAction: 2);
Out.ar([0,1], signal);
)

g = Synth(\mySynth4);
\end{lstlisting}

\end{document}

• This does not seem to be related to memoir at all so I suggest removing the memoir tag. If you want help you need to provide example code that others can test. Given that this is via R markdown (which not many people here know anything about, it is probably best to provide examples of the latex code generated from R Markdown Jun 18 at 12:53
• @daleif I removed the memoir tag 👍 In terms of the code produced it is simply \lstinline{} tags around the inline code. Jun 18 at 12:56
• Thanks. You should provide a document that uses \lstinline than. People are much more inclined to help if they have code to work with. Jun 18 at 13:07
• @daleif the problem is that I am compiling from RMarkdown to pdf so any code would be a hello world latex example that uses a \lstinline tag and that is all 🤷‍♂️ Jun 18 at 13:14
• @daleif I've added the MWE 👍 Jun 18 at 14:21

This was a tricky one and the (specific to RMarkdown) solution was to use tcolorbox as per @daleif's suggestion in combination with a pandoc lua filter to apply the box globally.

% ------------------------------------------------------------
% style all inline code with borders using tcolorbox
% I am using a lua filter to convert \lstinline to \scinline
\usepackage[most, breakable]{tcolorbox}
\DeclareTotalTCBox{\scinline}{ s v } {
verbatim,
sharp corners,
colupper=black,
colback=white,
arc=0.5mm,
size=fbox,
boxsep=1.3pt,
colframe=code-border} {
\lstinline[]^#2^
}


the lua filter:

if FORMAT:match 'latex' then
function Code (element)
local text = element.text
return {
pandoc.RawInline(
'latex',
'\\scinline{' .. text .. "}"
),
}
end
end