Im writing a report in overleaf about a programming language im making, I want to be able to use listings to have the syntax of the language highlighted in the report, however since the programming language have keywords in danish, some words are special characters, how do I make the special characters æ, ø and å highlighted, as part of a keyword?
An excerpt of my file is shown below, with an example of text. It should include all from my preamble that are relevant for this question.
\documentclass[12pt,oneside,a4paper,openright]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[sc]{mathpazo}
\usepackage[utf8]{inputenc}
\usepackage[danish, english]{babel}
\usepackage{xcolor}
\usepackage{graphicx}
% Colors for Code
\definecolor{grayC}{RGB}{250,250,250}
\definecolor{Dgray}{RGB}{200,200,200}
\definecolor{bluekeywords}{rgb}{0,0,1}
\definecolor{greencomments}{rgb}{0,0.5,0}
\definecolor{redstrings}{rgb}{0.64,0.08,0.08}
\definecolor{xmlcomments}{rgb}{0.5,0.5,0.5}
\definecolor{types}{rgb}{0.17,0.57,0.68}
\usepackage{listings}
\lstset{
literate= {Ø}{{\O}}1 {Æ}{{\AE}}1 {Å}{{\AA}}1
}
\lstdefinelanguage{BABs} {
alsoletter={\O,\AE,\AA},
morekeywords={
HVIS,
GØR,
FÆRDIG,
ER,
IKKE,
OG,
ELLER,
GENTAG,
OPDATER,
TABEL,
RÆKKE,
VIS,
INDLÆS,
SANDHEDSVÆRDI,
TEKST,
DECIMALTAL,
HELTAL,
SAND,
FALSK
},
sensitive = false, % No case sensitivity of keywords
morecomment = [s]{\#}{\#}, % Comment with start and end
morestring = [b]" % Strings are enclosed with "
}
% Some additional settings for BABs
\lstset{language=BABs,
backgroundcolor=\color{grayC},
basicstyle=\ttfamily\small,
breakatwhitespace=false,
breaklines=true,
commentstyle=\color{greencomments},
deletekeywords={...},
escapeinside={(*@}{@*)},
extendedchars=true,
frame=single,
keepspaces=true,
keywordstyle=\color{bluekeywords},
numbers=left,
numbersep=5pt,
numberstyle=\tiny\color{black},
rulecolor=\color{Dgray},
showspaces=false,
showstringspaces=false,
showtabs=false,
stepnumber=1,
stringstyle=\color{redstrings},
tabsize=2
}
\begin{document}
This is a test to show that \lstinline[language=BABs]|GØR{<Stmts>}| and \lstinline[language=BABs]{FÆRDIG} are not properly highlighted, however \lstinline[language=BABs]{HVIS(<BoolExpr>)} is.
\end{document}
Output:
As can be seen FÆRDIG
and GØR
are not highlighted as keywords, eventhough they are specified using morekeywords
and I have added them as letters using alsoletter
. The exerpt above, have been made by looking at solutions to similar problems, where the special characters are - or . instead.
Does anyone know how to make it work in my case with the danish keywords containing special characters?