The Czech original can be read here.
Over the many years I've been using Latex for typesetting all sorts of things, I've perfected my Biblatex settings to perfection. (I have the most beautiful citations west of the Mississippi.😉) When I recently switched to Typst (a more modern typesetting system that doesn't make you pull your hair out as much), one of the things that surprised me was the – in my opinion – unattractive bibliography. Here is my cobbled-together attempt to solve this problem!
Bibliography in Typst
First, it's necessary to (at least briefly) explain how bibliography works in Typst. From a user's perspective, it's quite simple: At the end of the document, you simply give a command to print the citation records (bibliography), in which you specify the list of literature and its style:
#bibliography("bibliografie.bib", style: "ieee")
In the text, you then simply refer to individual works, e.g. @jirasek[str. 12]
.
Boom, done.
Unlike in Latex, you don't have to worry about multiple compilations or which package to use.
The list of literature can be either in a .bib
file, which is also used by Biblatex, or in a .yml
file in the Hayagriva format.
Hayagriva appears to be the canonical format, so if you're using the Biblatex format, it will be converted upon loading.¹
(Currently, the conversion is not lossless:
The note
field may be lost.)
Typst has several built-in citation styles (such as APA, IEEE, and the English variant of ISO 690). However, if you want auA0different citation style, you need to provide Typst with a CSL file that describes the desired style. (CSL can define rules like: Print authors' surnames in small caps, print the title of the work in italics, etc.) And here lies my problem with creating a bibliography in Typst: Although there are several CSL implementations of (my preferred citation standard) ISO 690, none of them suit me. (For example, the implementation of the Czech variant of ISO 690 that I found uses short numbering for journals instead of long numbering: 10(2) instead of vol. 10, no. 2. Both the built-in style and the styles from the internet had missing periods and spaces, etc.) I don't dare to implement ISO 690 myself or modify someone else's style because working with CSL is – as is commonly known – a real pain in the arse.
Bashing and hacking
If I had a similar problem in LaTeX, I could write the citations by hand (and possibly have them generated by a script).
However, in Typst, manual citations aren't a thing.²
But that couldn't stop me.
After a bit of thinking, I came up with this diagram:
The work plan was as follows:
- create citation records in plain text;
- dump these preformatted records into a fake
.bib
or.yml
file; - typeset them in Typst using a custom CSL.
Step 1: Creting the citation records
First, it is necessary to create the actual citation records.
Having a list of books and articles jazykověda.bib
, I set out to create a Latex file citace.tex
which prints out only the citation records.
It looked roughly like this:
first version of
citace.tex
\documentclass{scrartcl}
\usepackage[czech]{babel}
\usepackage[
backend = biber,
style = iso-numeric
]{biblatex}
\addbibresource{jazykověda.bib}
\begin{document}
\pagenumbering{gobble}
\nocite{*}
\printbibliography[env = mypubs, heading = none]
\end{document}
Latex translates this code into a multi-page list of (beautiful) citation records.
However, I wanted to avoid using Latex. After all, Latex takes a long time to compile code into PDFs. (By the way, Typst generates PDFs swiftly.) If you ask the internet how to convert LaTeX code to plain text, you'll will receive a simple answer: Use Pandoc! I gave it a try. The first command
pandoc
citace.tex
-f latex
-t html
--verbose -s
-o citace.html
--bibliography jazykověda.bib
resulted in a blank page.³
The second command
pandoc
citace.tex
-f latex
-t html
--verbose -s
-o citace.html
--citepro
--bibliography jazykověda.bib
did output some records.
However, they didn't conform to ISO 690 and certainly not to my Latex file:

Using Pandoc didn't work out.
Therefore, I decided to create a PDF using Latex and then convert it to plain text using the pdftotext
.
First, I had to adjust the LaTeX code so that the PDF wouldn't contain any messy formatting that could spill over into plain text.
The new citace.tex
looked like this:
second version of
citace.tex
\documentclass[
fontsize = 9
]{scrartcl}
\usepackage[czech]{babel}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage[
unicode,
hidelinks
]{hyperref}
\usepackage[
maxbibnames = 5,
maxcitenames = 3,
mincitenames = 1,
uniquename = init,
uniquelist = false,
backend = biber,
style = iso-numeric,
sorting = none,
articlepubinfo = true,
mincrossrefs = 99,
doi = false
]{biblatex}
\addbibresource{jazykověda.bib}
\geometry{
paperheight = 1189mm,
paperwidth = 594mm,
left = 1mm,
right = 1mm,
top = 1mm,
bottom = 1mm
}
\renewcommand*{\mkbibacro}[1]{%
{#1}%
}
\DefineBibliographyStrings{czech}{andothers={a~kol\adddot}}
\DefineBibliographyStrings{slovak}{andothers={a~kol\adddot}}
\DefineBibliographyStrings{english}{andothers={a~kol\adddot}}
\DefineBibliographyStrings{german}{andothers={a~kol\adddot}}
\DefineBibliographyStrings{czech}{bathesis={Bakalářská práce}}
\DefineBibliographyStrings{czech}{mathesis={Diplomová práce}}
\DefineBibliographyStrings{czech}{phdthesis={Dizertační práce}}
\DefineBibliographyStrings{czech}{
editor = {ed\adddot},
editors = {ed\adddot},
bytranslator = {Překlad},
}
\DefineBibliographyStrings{english}{
editor = {ed\adddot},
editors = {ed\adddot},
bytranslator = {Překlad},
}
\DefineBibliographyStrings{german}{
editor = {ed\adddot},
editors = {ed\adddot},
bytranslator = {Překlad},
}
% \let\familynameformat=\textsc
\DefineBibliographyStrings{czech}{
page={str.},
pages={str.},
}
\DeclareNameAlias{bytranslator}{given-family}
\newbibmacro{titles}[2]{%
\ifboolexpr{
test {\iffieldundef{#1title}}
and
test {\iffieldundef{#1subtitle}}}
{}
{\printtext[#2]{%
¦%
\printfield{#1title}%
\setunit{\subtitlepunct}%
\printfield{#1subtitle}}%
\setunit{\addspace}}%
¦%
\printfield{#1titleaddon}%
\newunit
}%
% https://tex.stackexchange.com/a/138886
\defbibenvironment{mypubs}
{\list
{}
{\setlength{\leftmargin}{\bibhang}%
\setlength{\itemindent}{-\leftmargin}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}}
{\endlist}
{\item}
\begin{document}
\pagenumbering{gobble}
\nocite{*}
\leavevmode
\printbibliography[env = mypubs, heading = none]
\end{document}
The output PDF looked like this and the converted plain text looked like this.
The PDF file citace.pdf
has only one page because of the aforementioned "mess".
Book and journal titles are separated by the ¦
character because of the subsequent parsing.
In citace.txt
, each record corresponds to one line, with the records sorted in the same order as in jazykověda.bib
.
Step 2: Fake .bib
The next step was to stuff the generated citation entries into a "fake" list of works, i.e. a .bib
file.
Each line (citation entry) from the file citace.txt
was divided into three parts:
- the part before italics (i.e. author names, possibly author names and article title),
- the part in italics (i.e. book title, journal title),
- the part after italics (i.e. publishing details).
.bib
file looked like this:
@book{kvan:tesitelova-1987,
title = {TĚŠITELOVÁ, Marie a kol. },
publisher = {O češtině v číslech},
location = {. 1. vyd. Praha: Academia, 1987.}
}
Here is the script with which I did it:
script for creating the fake
.bib
file#!/usr/bin/env python3
import bibpy
def main():
with open('citace.txt', 'r') as file:
text_input = file.readlines()
lines = [line.strip().split('¦') for line in text_input[:-2]]
bibliography = bibpy.read_file('jazykověda.bib').entries
if len(lines) != len(bibliography):
return 1
for i in range(len(lines)):
if len(lines[i]) == 5:
first_part = lines[i][0] + lines[i][1] + lines[i][2]
middle_part = lines[i][3]
last_part = lines[i][4]
elif len(lines[i]) == 3:
first_part = lines[i][0]
middle_part = lines[i][1]
last_part = lines[i][2]
else:
print('divná délka')
print(f'@book\u007b{bibliography[i].bibkey},')
print(f'\ttitle = \u007b{first_part}\u007d,')
print(f'\tpublisher = \u007b{middle_part}\u007d,')
print(f'\tlocation = \u007b{last_part}\u007d')
print('\u007d')
return
if __name__ == '__main__':
main()
Step 3: CSL
The last thing left to do was to create a CSL style that would correctly typeset my fake bibliography.
It should set the title
field in regular font, followed by the publisher
field in italics, and then the location
field again in regular font.
Fortunately, this wasn't as complicated as a full implementation of ISO 690.
My CSL style fake_bib.csl
looks like this:
fake_bib.csl
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="never" default-locale="cs-CZ">
<info>
<title>Fake BIB</title>
<id>fake_bib</id>
<author>
<name>T. V.</name>
</author>
<category citation-format="numeric"/>
<category field="generic-base"/>
<summary>Fake BIB</summary>
</info>
<citation collapse="citation-number" after-collapse-delimiter="; ">
<sort>
<key variable="citation-number"/>
</sort>
<layout prefix="[" suffix="]" delimiter=", ">
<group delimiter=" ">
<text variable="citation-number"/>
<group delimiter=" ">
<label variable="locator" form="short"/>
<text variable="locator"/>
</group>
</group>
</layout>
</citation>
<bibliography second-field-align="flush">
<layout>
<text variable="citation-number" prefix="[" suffix="] "/>
<text variable="title" suffix=" "/>
<text variable="publisher" font-style="italic" suffix=" "/>
<text variable="publisher-place"/>
</layout>
</bibliography>
</style>
The End
Hotovo! Simply generate a dummy list, feed it to Typst (along with fake_bib.csl
), and take delight in the beautiful citations.
Check it out!
-
It's not really a conversion per se.
Rather, Typst uses the Hayagriva library, which can handle biblatex files, but primarily works with the mentioned
.yml
files. - I am lying a bit. Someone has already figured out one way to do it.
- I've tried both HTML and plain text conversion.