Important
This repo is inspired by the user cansik and his repository kotlin-latex-listing. Go check it out :)
I wrote my bachelor thesis a few weeks ago and wanted to show some Dart code in it. While reading the documentation for the listing package, I noticed that it does not support Dart. So I created a language template and wanted to share it with you here.
This is an example of how the highlighting looks. You can find the example code in the exampleCode.dart. Feel free to contribute to the styling with extra keywords or new styles :)
To use the styling copy the content of the dart-highlighting.tex into your LaTeX document like this:
\documentclass{...}
% Other packages
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}
\definecolor{green}{RGB}{60,160,0}
\definecolor{red}{RGB}{200,30,0}
\lstdefinelanguage{Dart}{
% Keywords
keywordstyle=\color{red},
morekeywords={
abstract, as, assert, async, await, break, case, catch, class, const, continue, default, do, else, enum, extends, extension, factory, false, final, finally, for, Function, get, if, in, is, late, library, mixin, new, null, on, operator, part, required, rethrow, return, set, show, static, super, switch, this, throw, true, try, typedef, var, void, while, with, yield, dynamic, export, external, implements, import, interface
},
% Flutter-specific Widgets
keywordstyle=[2]\color{green},
morekeywords=[2]{
Widget, StatelessWidget, StatefulWidget, Scaffold, AppBar, Column, Row, Container, Text, Image, ListView, Builder, FutureBuilder, StreamBuilder, MaterialApp, Theme, Material, Center, Padding, SizedBox, Expanded, Icon, ButtonStyle, ElevatedButton, TextButton, IconButton, FloatingActionButton, Navigator, Route, MaterialPageRoute, State, setState, BuildContext, Key, GlobalKey, Form, TextFormField, FormState, FocusNode, EdgeInsets, Colors, ThemeData, MediaQuery, Orientation, Axis, MainAxisAlignment, CrossAxisAlignment, TextStyle, FontWeight, TextAlign, BoxDecoration, BorderRadius, BoxShadow, Alignment, Curve, Duration, Animation, AnimationController, Tween, Hero, GestureDetector, InkWell, Divider, CircleAvatar, ClipRRect, SafeArea, SingleChildScrollView, Wrap, Stack, Positioned, Opacity, Transform, AnimatedContainer, AnimatedOpacity, Future, Stream, Iterable, Map, List, Set, DateTime, RegExp, Uri, http, json, dart, async, await, FutureBuilder, StreamBuilder
},
% Datatypes
keywordstyle=[3]\color{green},
morekeywords=[3]{
int, double, num, String, bool, List, Map, Set, Iterable, Future, Stream, dynamic, Object, Type, Never, void, Function, Symbol, Runnable, Comparable, Pattern, Match, RegExpMatch, StackTrace, Exception, Error, TypeError, FormatException, IOException, ArgumentError, RangeError, UnsupportedError, StateError, TimeoutException, Null, Nullable
},
% Directives
keywordstyle=[4]\color{teal},
morekeywords=[4]{
@override, @required, @Deprecated, @protected, @visibleForTesting, @immutable, @factory, @sealed, @mustCallSuper, @nonVirtual
},
% Strings
stringstyle=\color{orange},
morestring=[b]", % double quote
morestring=[b]', % single quote
morestring=[b]""", % multi-line string
morestring=[b]''', % multi-line string
% Comments
commentstyle=\color{gray},
morecomment=[l]{//}, % single-line
morecomment=[s]{/*}{*/}, % multi-line
morecomment=[l]{///}, % Flutter doc comment
morecomment=[s]{/**}{*/}, % Java doc comment (multi-line)
}
\begin{document}
\end{document}You can also use my listing style as shown in the example.tex to achieve the exact listing style you see in the example picture
When you copied the language definition into your project, you can use it as following:
\begin{lstlisting}[caption=Dart syntax highlighting, language=Dart]
// This is a simple dart listing
print("Hello World");
\end{lstlisting}This will look like this:
Feel free to contribute to this repo to add missing keyword, enhance styling or whatever :)

