A syntax highlighting template for the Kotlin language in LaTeX listings.

Overview

Kotlin for LaTeX Listings Build LaTeX

Currently, I am writing my bachelor thesis with Kotlin and need to document some code in LaTeX. The lstpackage does not support kotlin syntax highlighting by default, so I decided to create a language template for it.

Example

Check out this example of the default style or download the whole document.

Feel free to add more keywords or new styles!

How to use it?

First of all you have to copy the language definition into your latex document:

\usepackage[dvipsnames]{xcolor}
\usepackage{listings}

\lstdefinelanguage{Kotlin}{
  comment=[l]{//},
  commentstyle={\color{gray}\ttfamily},
  emph={filter, first, firstOrNull, forEach, lazy, map, mapNotNull, println},
  emphstyle={\color{OrangeRed}},
  identifierstyle=\color{black},
  keywords={!in, !is, abstract, actual, annotation, as, as?, break, by, catch, class, companion, const, constructor, continue, crossinline, data, delegate, do, dynamic, else, enum, expect, external, false, field, file, final, finally, for, fun, get, if, import, in, infix, init, inline, inner, interface, internal, is, lateinit, noinline, null, object, open, operator, out, override, package, param, private, property, protected, public, receiveris, reified, return, return@, sealed, set, setparam, super, suspend, tailrec, this, throw, true, try, typealias, typeof, val, var, vararg, when, where, while},
  keywordstyle={\color{NavyBlue}\bfseries},
  morecomment=[s]{/*}{*/},
  morestring=[b]",
  morestring=[s]{"""*}{*"""},
  ndkeywords={@Deprecated, @JvmField, @JvmName, @JvmOverloads, @JvmStatic, @JvmSynthetic, Array, Byte, Double, Float, Int, Integer, Iterable, Long, Runnable, Short, String, Any, Unit, Nothing},
  ndkeywordstyle={\color{BurntOrange}\bfseries},
  sensitive=true,
  stringstyle={\color{ForestGreen}\ttfamily},
}

Then you have to set the language of your listing to Kotlin:

\begin{lstlisting}[caption={Simple code listing.}, label={lst:example1}, language=Kotlin]
// this is a simple code listing:
println("hello kotlin from latex")
\end{lstlisting}

And finally your listing should look like this: Simple Example (The border is not part of the language definition. Check out the example.tex for this style.)

Contributors

Feel free to add new or missing keywords and style enhancements. Just create a pull request. The github actions command automatically builds the example PDF and PNG and uploads it to the Example release.

Thanks to @ppizarror, @ice1000, @etwasanderes2

You might also like...
KVision allows you to build modern web applications with the Kotlin language

KVision allows you to build modern web applications with the Kotlin language, without any use of HTML, CSS or JavaScript. It gives you a rich hierarchy of ready to use GUI components, which can be used as builder blocks for the application UI.

A coding examples project about Kotlin Programming language. 🇰
A coding examples project about Kotlin Programming language. 🇰

Kotlin Tutorial 👨🏻‍💻 What is Kotlin ❓ Kotlin is a new programming language, developed by JetBrains. Jetbrains is a popular software development com

This is a template to help you get started building amazing Kotlin applications and libraries.

Welcome to the Starter This is a template to help you get started building amazing Kotlin applications and libraries. Over time, examples will be comp

 KMMT : Kotlin Multiplatform Mobile Template
KMMT : Kotlin Multiplatform Mobile Template

Kotlin Multiplatform Mobile App Template

Template for building CLI tool in Kotlin and producing native binary

Kotlin command-line native tool template This template allows you to quickly build command-line tool using Kotlin , Clikt and build a native binary fo

 Hexagonal Architecture Kotlin Template
Hexagonal Architecture Kotlin Template

The purpose of this template is to avoid repeating, over and over again, the same basic packages structure, gradle and configurations.

For Kotlin with SpringBoot project that have multi-module-structure template

Goals kotlin + spring-boot + gradle + multi-module building Module-Structure ---root |--- src.main.kotlin.KotlinSpringbootMultiModuleTemplateAppl

An Android template you can use to build your project with gradle kotlin dsl

Android Gradle KTS An Android template you can use to build your project with gradle kotlin dsl Build.gradle.kts You can use your project's build.grad

Minecraft Forge Kotlin Template

Minecraft Forge Kotlin Template Minecraft 1.12.2 で Forge と Kotlin を用いた Mod のテンプレートです。 Minecraft 1.12.2 Mod template using Forge and Kotlin. Getting St

Comments
  • Updated latex code

    Updated latex code

    Several changes have been made:

    • Sorted listing keys by name.
    • Sorted kotlin keywords by name.
    • Added some {} parenthesis around color definition in order to fix some bugs i had when using this my template.
    • Deleted repeated 'object' from keywords.
    opened by ppizarror 1
  • Add more keywords, some refactors

    Add more keywords, some refactors

    Changes

    • Add all keywords from The Kotlin Reference.
    • Move kotlin code into separate .kt files.
    • Move tex definition of kotlin language into septarate .tex file.
    • Extra code for the example.

    Controversial Changes

    • delegate, return@: moved from emph to keywords
    • !in, !is: The exclamation mark (!) is part of the keyword.
    opened by etwasanderes2 0
Releases(example)
Owner
Florian Bruggisser
Software developer with interests in computer graphics, generative art and realtime visual performance.
Florian Bruggisser
An Interpreter/Transpiler for the Folders esoteric programming language, a language with no code and just folders

Folders2kt ?? An Interpreter/Transpiler of the Folders esoteric programming language, a language with no code and just folders, written in Kotlin Show

Jens Klingenberg 18 Jan 4, 2023
Scala 3 Standard Library with bracket syntax.

Scala 3 Library with braces Scala adds a terrible new feature, optional braces, which allow use indentation instead of braces. The new syntax is widel

Glavo 10 Dec 30, 2021
A funny project to help you test your BNF syntax

Readme The idea of this project is to implement a BNF expression compiler. We could use BNF to design some syntax like Arithmetic expression. <factor>

Jack Chen 4 Dec 21, 2022
It is a project that contains lessons and examples about Kotlin programming language. 🇰

Kotlin Tutorials What is Kotlin? I added the platforms it supports and great resources. You can access the article from the link below: https://medium

Halil Özel 94 Dec 22, 2022
A showcase music app for Android entirely written using Kotlin language

Bandhook Kotlin This project is a small replica of the app I developed some time ago. Bandhook can still be found on Play Store At the moment it will

Antonio Leiva 1.9k Dec 23, 2022
101 examples for Kotlin Programming language.

This is a collection of runnable console applications that highlights the features of Kotlin programming language. The use of console application enab

Dody Gunawinata 192 Dec 1, 2022
Android Multi Theme Switch Library ,use kotlin language ,coroutine ,and so on ...

Magic Mistletoe Android多主题(换肤)切换框架 背景 时隔四年,在网易换肤之前的思路下,做了几点改进,现在完全通过反射创建View,并且在SkinLoadManager中提供一个configCustomAttrs以支持自定义View的属性插队替换 摈弃了之前的AsyncTask

Mistletoe 18 Jun 17, 2022
The Okila server project uses the Spring boot framework and uses the Kotlin language

Okila-Server The Okila server project uses the Spring boot framework and uses the Kotlin language Format Response //The response successfully format

Nankai 1 Oct 25, 2021
Practising kotlin language

Kotlin Learning About this project : 1.Starting with kotlin. 2.Creating a birthday wishing program. ?? Tech Stack: [] [] ?? Main Page: HELLO WORLD BIR

Shruti Mishra 0 Dec 4, 2021
Demonstration of Object Pool Design Pattern using Kotlin language and Coroutine

Object Pool Design Pattern with Kotlin Demonstration of Thread Safe Object Pool Design Pattern using Kotlin language and Coroutine. Abstract The objec

Enes Kayıklık 7 Apr 12, 2022