So I want to show some python, bash and terminal output using the listing package.
I searched for some language definitions for bash and python for the listing package and in the beginning it worked really good. Now I wanted to add some terminal output but I found that only the last defined language is used for all listings, no mather what language I manually define for the given listing.
I made up an basic example on overleaf:
https://www.overleaf.com/18688751pxczqpkbbkyg#/70340370/
Problem is, this example doesn't really gives the same result on overleaf as I am experiencing here on my local document.
What am I doing wrong? I just want to add some color highlighting for python and bash scripts and some blank code for the terminal output.
Edit: here's the code:
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage[procnames]{listings}
\begin{filecontents}{00_python.py}
# Image processing
from PIL import Image
import numpy as np
image_dimensions = 224
# Image paths
train_dir = "/path/to/train"
validation_dir = "/path/to/train"
\end{filecontents}
\begin{filecontents}{00_terminal.txt}
test@ubuntu-vm:~/Desktop$ time ./00_preprocess_and_sort.sh
Getting variables...Done
input dir: /home/test/new/00_data/00_all
sorted dir: /home/test/new/00_data/01_sorted
backup dir (attr.): /home/test/new/00_data/00_all_backup_attributes
backup dir: /home/test/new/00_data/00_all_backup
id dir: /home/test/new/00_data/03_ids
stats dir: /home/test/new/00_data/04_statistics
\end{filecontents}
\begin{filecontents}{00_bash.sh}
#!/ bin/ bash
printf " Getting variables ... "
INPUT_DIR =~/ new /00 _data /00 _all
ID_DIR =~/ new /00 _data /03 _ids
SORTED_DIR =~/ new /00 _data /01 _sorted
BACKUP_DIR_ATTRIBUTES =~/ new /00 _data /00 _all_backup_attributes
BACKUP_DIR =~/ new /00 _data /00 _all_backup
STATISTIC_DIR =~/ new /00 _data /04 _statistics
\end{filecontents}
\definecolor{keywords}{RGB}{255,0,90}
\definecolor{comments}{RGB}{0,0,113}
\definecolor{red}{RGB}{160,0,0}
\definecolor{green}{RGB}{0,150,0}
\lstset{language=python,
basicstyle=\itshape\small,
keywordstyle=\color{keywords},
commentstyle=\color{comments},
stringstyle=\color{red},
showstringspaces=false,
identifierstyle=\color{green},
procnamekeys={def,class}
}
\lstset{language=bash,
basicstyle=\bfseries,
showstringspaces=false,
commentstyle=\color{red},
keywordstyle=\color{blue}
}
\begin{document}
\lstinputlisting[language=bash, breaklines=true, title={Bash script}, frame=tb]{00_bash.sh}
\lstinputlisting[language=python, breaklines=true, title={Python code}, frame=tb]{00_python.py}
\lstinputlisting[breaklines=true, title={Terminal output}, frame=tb]{00_terminal.txt}
\end{document}
\lstsetjust sets the globallistingsoptions. That means that several\lstsets overwrite each other with the last one winning, furthermore their settings are overruled by local settings. I guess you want something like\lstdefinestyle(or maybe\lstdefinelanguage). (Also, please consider adding the code (in reduced form) directly to your question. Not all people like to follow links to third-party sites and you never know when that link becomes unreachable.) – moewe Aug 30 '18 at 09:18\lstsetand\lstdefinestyle. – moewe Aug 30 '18 at 09:21\lstdefinestyleworks. Can you explain in more detail what you want, why and how\lstdefinestyledoes not work and add a static version of the code that does not change to your question, please? – moewe Aug 30 '18 at 09:28listingsis a bit outdated. Maybe some language definitions changed in the meantime, that could explain slight differences in highlighting. – moewe Aug 30 '18 at 09:29