0

I am writing a document in Latex (pdflatex) and I am bound to use a predefined custom style. Now, I want/need to print a code listing using \lstlisting, which I need to be monospaced sans-serif.

My problem is now, that listings I create are monospaced, but NOT sans-serif. Whatever I try, my listings end up being serif. And I need to change that.

The style is extensive (more than 1500 lines) and must not be altered, hence pasting it in its entirety is I guess not helping.

Anyhow I went though it and think I identified the interesting parts:

\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage{lmodern,textcomp}
\RequirePackage{microtype}
\RequirePackage[ngerman]{babel}
\RequirePackage{ae,pifont}              
\Requirepackage{courier}

% ...

\usepackage{listings}
\lstloadlanguages{
    [Visual]Basic,
    Pascal,
    C,
    [ISO]C++,
    XML,
    HTML,
    Java,
    bash
}
\lstset{
    breakatwhitespace=false,
    upquote=true,
    keepspaces=true,
    language=Java,
    numbers=none,
    numbersep=5pt,
    tabsize=2,
    extendedchars=true,
    breaklines=true,
    basicstyle=\scriptsize\ttfamily\color{basicStyleColor},
    identifierstyle=\color{identifierStyleColor},
    keywordstyle=[1]\color{keywordStyle1Color},
    keywordstyle=[2]\color{keywordStyle2Color},
    keywordstyle=[3]\color{keywordStyle3Color},
    stringstyle=\color{stringStyleColor},
    commentstyle=\itshape\color{commentStyleColor},
    numberstyle=\tiny\color{commentStyleColor},
    rulecolor=\color{black},
    showspaces=false,
    showtabs=false,
    xleftmargin=17pt,
    frame=none,
    framexleftmargin=17pt,
    %framexrightmargin=5pt,
    framexbottommargin=4pt,
    %backgroundcolor=\color{lightgray},
    showstringspaces=false,
      {á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1
      {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1
      {à}{{\`a}}1 {è}{{\`e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1 {ù}{{\`u}}1
      {À}{{\`A}}1 {È}{{\'E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ù}{{\`U}}1
      {ä}{{\"a}}1 {ë}{{\"e}}1 {ï}{{\"i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1
      {Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1
      {â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1
      {Â}{{\^A}}1 {Ê}{{\^E}}1 {Î}{{\^I}}1 {Ô}{{\^O}}1 {Û}{{\^U}}1
      {œ}{{\oe}}1 {Œ}{{\OE}}1 {æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1
      {ű}{{\H{u}}}1 {Ű}{{\H{U}}}1 {ő}{{\H{o}}}1 {Ő}{{\H{O}}}1
      {ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\r a}}1 {Å}{{\r A}}1
      {€}{{\euro}}1 {£}{{\pounds}}1 {«}{{\guillemotleft}}1
      {»}{{\guillemotright}}1 {ñ}{{\~n}}1 {Ñ}{{\~N}}1 {¿}{{?`}}1
      {€}{{\texteuro}}1
}

with the document preamble being

\documentclass[12pt]{mystyle}

\usepackage{ulem}
\usepackage{enumerate}

\begin{document}
    \sloppy

Now, I want to print something like this and want it to be in sans-serif font:

\begin{lstlisting}
import akka.actor.{ActorSystem, Props}

object Main extends App {
}
\end{lstlisting}

But no matter what I do, the font always remains the same for the listings.

How do I change the font for the listings (Meaning: not just the font-family (\tttype), but the entire font?) while at the same time NOT changing the font for the rest of the document?

Xenonite
  • 225
  • 1
    Which font do you want to use? Unrelated: don't use the ae package, that it quite unneeded today. – Ulrike Fischer Jul 22 '19 at 13:05
  • I was thinking arial, but since this is not a standard font, i would go for droid sans – Xenonite Jul 22 '19 at 13:50
  • Neither arial nor droid sans is a monospaced font. – Ulrike Fischer Jul 22 '19 at 13:54
  • Isn't this a duplicate of https://tex.stackexchange.com/questions/413586/how-to-get-a-monospaced-sans-serif-font-for-the-source-code-when-using-lstinputl ? – Marijn Jul 22 '19 at 13:55
  • Or maybe https://tex.stackexchange.com/questions/297483/listing-with-monospaced-font-dejavu-sans-mono-and-background-color , also monospaced and sans serif. – Marijn Jul 22 '19 at 13:58
  • Or https://tex.stackexchange.com/questions/174892/what-is-the-least-invasive-way-to-set-the-font-for-listings for a different approach without font packages. – Marijn Jul 22 '19 at 14:00
  • then about any monospaced, non-serif font for the listings, but another, serif-font for the text. possible? – Xenonite Jul 23 '19 at 08:10
  • @Xenonite that is possible, all three questions in my previous comments have different fonts for the listings and the main text, in the first and third linked question the main font is serif. – Marijn Jul 24 '19 at 08:06

0 Answers0