1

I set 3 styles in my lecture notes for 3 different code style enviroments (\lstdefinestyle and \lstnewenvironment). How can I set the \lstinline style to one of these? Or is it not possible?

Because the lstinline has very small font now and is not uniform with the normal text. (the documentation doesn't really help there? :/)

Here is an example code

\documentclass[12pt,twoside,a4paper,fleqn,ngerman]{report} %Koma-Script Class article

\RequirePackage{listings}               % Programmierprachen
\let\l\lstinline
\let\t\text
\RequirePackage{lmodern}                % customized font size 
\RequirePackage{color}
\definecolor{mygray}{rgb}{0.31,0.31,0.31}

% style for appendix with smaller size for the appendix with custom size 9pt
\lstdefinestyle{small_customf95}{
    % belowcaptionskip=1\baselineskip,
    breaklines=true,
    frame=none,
    xleftmargin=0.5cm,
    language=[95]Fortran,
    showstringspaces=false,
    basicstyle=\footnotesize\ttfamily,
    keywordstyle=\bfseries,
    commentstyle=\color{mygray},
    % identifierstyle=\color{blue},
    % stringstyle=\color{orange},
}
\lstset{mathescape=true,escapeinside={@}{@},style=small_customf95}

\lstnewenvironment{smallf95}{%
    \lstset{%
        mathescape=true,escapeinside={@}{@},style=small_customf95,
    }
}{}

% style for appendix with smaller size for the appendix with custom size 9pt, very small !!! only use
%if the other size is still to big !!!
\lstdefinestyle{smaller_customf95}{
    % belowcaptionskip=1\baselineskip,
    breaklines=true,
    frame=none,
    xleftmargin=0.5cm,
    language=[95]Fortran,
    showstringspaces=false,
    basicstyle=\fontsize{9pt}{9pt}\ttfamily,
    keywordstyle=\bfseries,
    commentstyle=\color{mygray},
    % identifierstyle=\color{blue},
    % stringstyle=\color{orange},
}
\lstset{mathescape=true,escapeinside={@}{@},style=smaller_customf95}

\lstnewenvironment{smallerf95}{%
    \lstset{%
        mathescape=true,escapeinside={@}{@},style=smaller_customf95,
    }
}{}

%default style for F95 code for the actual lectures, size 8pt
\lstdefinestyle{customf95}{
    % belowcaptionskip=1\baselineskip,
    breaklines=true,
    frame=none,
    xleftmargin=0.5cm,
    language=[95]Fortran,
    showstringspaces=false,
    basicstyle=\small\ttfamily,
    keywordstyle=\bfseries,
    commentstyle=\color{mygray},
    % identifierstyle=\color{blue},
    % stringstyle=\color{orange},
}
%\lstset{mathescape=true,escapeinside={@}{@},style=customf95}
\lstnewenvironment{basicf95}{%
    \lstset{%
        mathescape=true,escapeinside={@}{@},style=customf95
    }
}{}

\begin{document}
    test \l{ADVANCE=?}.
\begin{basicf95}
    PROGRAM test
        IF blabla
            ...
        END IF
    END PROGRAM test
\end{basicf95}
\l{ADVANCE=?} - now?
\end{document}
2
  • Welcome to TeX.SE... Please always post your MWE, i.e., from \documentclass to \end{document} that will help others to understand the exact problem and also helps to give correct suggestion....
    – MadyYuvi
    Oct 19, 2020 at 14:24
  • see the pastebin example code.
    – Ameyah
    Oct 19, 2020 at 14:45

2 Answers 2

1

Just define one style and make the suitable adjustments when defining the environments: a change in the overall style will be reflected also in all three environments and in the inline version.

\documentclass[12pt,twoside,a4paper,fleqn,ngerman]{report} %Koma-Script Class article
\usepackage[T1]{fontenc}
\usepackage{babel}

\usepackage{listings}               % Programmierprachen
\usepackage{lmodern}                % customized font size 
\usepackage{color}

\definecolor{mygray}{rgb}{0.31,0.31,0.31}

% style for appendix with smaller size for the appendix with custom size 9pt

\lstdefinestyle{customf95}{
    % belowcaptionskip=1\baselineskip,
    breaklines=true,
    frame=none,
    xleftmargin=0.5cm,
    language=[95]Fortran,
    showstringspaces=false,
    keywordstyle=\bfseries,
    commentstyle=\color{mygray},
    % identifierstyle=\color{blue},
    % stringstyle=\color{orange},
    mathescape=true,
    escapeinside={@}{@},
}

\lstnewenvironment{basicf95}
 {%
  \lstset{
    style=customf95,
    basicstyle=\small\ttfamily,
  }%
 }{}

\lstnewenvironment{smallf95}
 {%
  \lstset{
    style=customf95,
    basicstyle=\footnotesize\ttfamily,
  }%
 }{}
\lstnewenvironment{smallerf95}
 {%
  \lstset{
    style=customf95,
    basicstyle=\fontsize{9pt}{11pt}\ttfamily,
  }%
 }{}
\newcommand{\inlinef}[1][]{%
  \lstinline[style=customf95,basicstyle=\ttfamily,#1]%
}


\begin{document}

test \inlinef{ADVANCE=?}.

\begin{basicf95}
    PROGRAM test
        IF blabla
            ...
        END IF
    END PROGRAM test
\end{basicf95}

\inlinef{ADVANCE=?} - now?

\begin{smallerf95}
    PROGRAM test
        IF blabla
            ...
        END IF
    END PROGRAM test
\end{smallerf95}

\inlinef{ADVANCE=?} - now?

\begin{smallf95}
    PROGRAM test
        IF blabla
            ...
        END IF
    END PROGRAM test
\end{smallf95}

\inlinef{ADVANCE=?} - now?

\end{document}

Avoid redefine \l and \t: when your bibliography will contain the name of some Polish author you'd regret having redefined \l.

enter image description here

1

The manual says, that \lstinline takes an optional argument, where you can set the style:

test \lstinline[style=customf95]{ADVANCE=?}.

enter image description here

Also, if you need short inline code, you can define

\lstMakeShortInline[style=customf95]|

Which can be used like shortvrb

test |ADVANCE=?|.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.