¿Cómo cambiar el tamaño de fuente **solo** para \lstinline{}?

¿Cómo cambiar el tamaño de fuente **solo** para \lstinline{}?

A primera vista, esto puede parecer un duplicado deotra preguntaya cerrado como duplicado deÉste. Pero no lo es ;-)

¿Cómo configuro?globalmente¿El tamaño de fuente de todas \lstinlinelas macros, independientemente del tamaño de fuente de lstlistinglos entornos?

El valor predeterminado que tengo para los entornos es \small, que se ve muy bien, pero necesito un tamaño normal para las líneas ya que se mezcla mejor con el texto circundante.

A continuación, según lo solicitado, un MWE que muestra la repetición de \lstsetmacros:

\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily\small,numbers=left}

\begin{document}

\begin{lstlisting}
Displayed code listings
    Look great
In a small font
\end{lstlisting}

I would like \lstinline{inline listings} to be at normalsize as in
\lstset{basicstyle=\ttfamily}%
\lstinline{this piece of code}
but then I have to issue a new \verb|lstset| macro
\lstset{basicstyle=\ttfamily\small}%
in order to get back to small size

\begin{lstlisting}
for displayed code listings
    to show appropiately.
again
\end{lstlisting}

\end{document}

ingrese la descripción de la imagen aquí

Respuesta1

¿Qué tal crear un nuevo comando como \myinlineen mi MWE?

\documentclass{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily\small,numbers=left}
\newcommand{\myinline}[1]{\lstinline[basicstyle={\ttfamily\normalsize}]{#1}}

\begin{document}

\begin{lstlisting}
Displayed code listings
    Look great
In a small font
\end{lstlisting}

I would like \lstinline{inline listings} to be at normalsize as in
\myinline{this piece of code}
but then I have to issue a new \verb|lstset| macro
in order to get back to small size

\begin{lstlisting}
for displayed code listings
    to show appropiately.
again
\end{lstlisting}

\end{document}

ingrese la descripción de la imagen aquí

Respuesta2

Mirando el código, no existe tal método para distinguir entre los dos. Pero parece que podemos crear uno porque \lstinlinese ejecuta \lstsetinternamente, por lo que podríamos agregar un parche. No tengo idea si esto tiene otras consecuencias.

\documentclass[a4paper]{article}
\usepackage{listings,xcolor,xpatch}

\lstset{
  basicstyle=\color{red}\ttfamily,
}

% style for inline
\lstdefinestyle{foobar}{
  basicstyle=\color{green}\ttfamily\tiny,
}

% \ShowCommand\lstinline shows \lstinline runs \lstset{flexiblecolumns,#1}, so we mess with that
\makeatletter
\xpatchcmd\lstinline{flexiblecolumns,}{flexiblecolumns,style=foobar,}{}{\typeout{patch failed}}
\makeatother


\begin{document}

\begin{lstlisting}
FooBar
\end{lstlisting}

inline \lstinline|FooBar|
\end{document}

ingrese la descripción de la imagen aquí

Respuesta3

Guardar \lstinlinecon otro nombre y redefinirlo para pasar el original también la opción basicstyle=\ttfamily(sin \small).

\documentclass{article}
\usepackage{listings}

\lstset{basicstyle=\ttfamily\small,numbers=left}

\NewCommandCopy{\originallstinline}{\lstinline}
\RenewDocumentCommand{\lstinline}{O{}}{%
  \originallstinline[basicstyle=\ttfamily,#1]%
}

\begin{document}

\begin{lstlisting}
Displayed code listings
    Look great
In a small font
\end{lstlisting}

Here I see that \lstinline{inline listings} is at normalsize
and there is no need to issue a new \verb|lstset| macro
in order to get back to small size

\begin{lstlisting}
for displayed code listings
    to show appropriately.
again
\end{lstlisting}

We can also pass options like in \lstinline[language=TeX]|\LaTeX|

\end{document}

ingrese la descripción de la imagen aquí

información relacionada