The Kalem Book GitHub

This Book describes Kalem's main branch, which may be ahead of the latest release.

LaTeX files

.tex files open rendered, as the document reads, and stay standard LaTeX byte for byte: nothing is rewritten, and what Kalem does not render stays as it is written. The source view (Ctrl+/) shows the text itself.

1. What is rendered

Structure
sectioning commands show as headings with the numbers LaTeX gives them, \paragraph as a bold heading in the text, \maketitle as the title, authors and date, and the front matter of IEEEtran, acmart, elsarticle, llncs and RevTeX as each class prints it. The preamble shows only its first line until the cursor enters it, and so does a long environment shown as source (a tikzpicture, say).
Text
\emph, \textbf, \texttt and their kin show their text styled, with the command and braces hidden until the cursor reaches them; ``, '', --, ---, ~, \&, \% and \\ show as the characters they typeset; center, flushleft, flushright, quote, quotation, verse and abstract are aligned or indented as LaTeX prints them. \footnote shows its raised number before its dimmed text, \url and \href are links, and comments, comment environments and \iffalse … \fi are dimmed and fold.
Lists
in itemize, enumerate and description each \item shows its bullet, its number in LaTeX's style for its depth (1., (a), i., or what enumitem's label and start say) or its own [label].
Formulas
$…$, \(…\), \[…\], $$…$$ and the math environments are typeset away from the cursor, equations with their numbers, using the document's macros. Theorems declared with \newtheorem show their names and numbers, and proof its "Proof." and ∎.
Figures and tables
\includegraphics shows the picture (PNG, JPEG, SVG, PDF or EPS, found where LaTeX looks: the root document's folder and the \graphicspath folders, with LaTeX's extensions when the name has none) at the width asked for, and \caption shows as "Figure 1: …" with LaTeX's number (Şekil and Tablo with babel's turkish). A tabular (also tabularx, array, longtable) written one row a line, with plain columns, shows as a grid with its rules until the cursor enters it, where Tab and Shift+Tab go from cell to cell; other tables stay as source.
Code
verbatim, lstlisting, minted, \verb and \lstinline are monospace, colored by the language their options name.
References and citations
\ref, \eqref, \cref, \autoref and \nameref show the numbers or titles they resolve to, in red as ?? when no \label has the key. Citations show the authors and years of the entries in the \bibliography or \addbibresource files, and the entry cited shows in the status bar and in a tooltip, formatted by the CSL style closest to the document's bibliography style. BibTeX entries pasted into the document go into its first bibliography file, and a \cite of them is pasted instead.

Open Link (Ctrl-click, Cmd-click on macOS) follows the command at the cursor: a reference to its \label, \url to the browser, \input, \include and \subfile to their file, \includegraphics to its picture, a citation to the bibliography file.

Documents of several files are numbered as one: the root is a % !TEX root line, the main file of a subfile, a NAME.tex.latexmain file, or the document up the folders that includes the file; each file shows the numbers it has in the whole document, and references to labels in the other files resolve. The outline panel (Ctrl+Shift+O) lists the sections with their numbers, a \tableofcontents line shows the table of contents LaTeX will print there, and the \end{document} line lists the document's footnotes.

2. Problems

What kalem check reports shows in the text a moment after typing stops: a red wavy line under problems (a group or environment left open, a label defined twice, an undefined reference or citation key, a missing file or picture) and a blue one under matters of style (\bf and its kin, $$, a space before \ref where ~ belongs, ..., "). The status bar, and a tooltip, say what it is. Quick Fix (Ctrl+., Alt+. in a terminal) makes the obvious change: \bfseries for \bf, ~ for the space, \ldots{} for ..., \[…\] for $$…$$. The errors and warnings of the last Build PDF are flagged on their lines too; Next Problem and Previous Problem (Alt+F8, Alt+Shift+F8) go from one to the next, and Show Problems lists them all.

3. Typing

  • " writes LaTeX's quotes, `` to open and '' to close; typed again right away, it is a plain " (not in languages where " is a shorthand, such as German).
  • Enter on a list item starts the next \item, and on an empty one leaves the list; Tab and Shift+Tab nest an item and take it out.
  • \begin{name} adds its \end{name}, and renaming one end of an environment renames the other.
  • Ctrl+B, Ctrl+I, Ctrl+U and Ctrl+Shift+K put \textbf, \emph, \underline and \texttt around the selection or the word, or take them off.
  • Ctrl+1 to Ctrl+6 make the line a heading of that level with the class's commands (\chapter first in books and reports, \section in articles), Ctrl+0 makes it text again, Alt+Shift+Left and Right promote and demote a section with its subsections, Alt+Shift+Up and Down move it past its neighbor, and Tab on a section's line folds it.
  • In math, $ pairs, \(, \[ and \left( get their closing pair, and Tab goes to the next empty {} or, in a matrix or cases, to the next cell; the formula shows rendered under the cursor as you type. Display Math turns $…$ into \[…\] and back, and Number Equation adds or takes off the star of the environment at the cursor.
  • Insert Figure, Insert Table (with booktabs' rules when the document loads it), Insert Equation and Insert Citation write the usual constructs with a caption and a label to fill.

Completion (as you type, or Ctrl+Space, Alt+/) offers commands after \, the document's macros and the commands of the packages the preamble loads included, environments after \begin{ and \end{, the bibliography's keys after \cite{ and its kin, labels after \ref{ and its kin with what they number, files after \input{ and \includegraphics{, and packages after \usepackage{.

4. Templates, export and building

New from Template… (File menu) writes a new document beside the current one from a template and opens it: an article, a report, a book, a beamer presentation, a letter, a CV, a thesis, or a Turkish thesis laid out as YÖK's guidelines ask. With pandoc installed, Export as HTML, Markdown and Word write the project's root document in those formats, and Convert to Org writes an Org file beside it; the LaTeX file stays as it is.

Build PDF (F5) builds the root document in the background with latexmk, or the engine alone with biber or bibtex between its runs: pdfLaTeX, the engine a % !TEX program = xelatex line or the latex.engine setting names, or XeLaTeX for documents that load fontspec. The status bar gives the first error at its file and line, or the PDF and the number of warnings; a missing package comes with the command that installs it; Cancel Build stops a build. latex.output_directory sends the output to a folder, latex.build_on_save builds on each save, and kalem latex build FILE does the same from the command line (--format json for the problems as data).

Builds write a SyncTeX file beside the PDF, which says where each source line is typeset. Show in PDF opens the PDF at the page of the cursor's line, in the files a root document includes too; in the PDF, Ctrl-click (Cmd-click on macOS) on a line of text opens the source file at the line it came from. A PDF built before has no SyncTeX file: build it again.

Coming from Emacs, LaTeX for AUCTeX users maps AUCTeX's and RefTeX's commands to Kalem's.

5. Beside Overleaf and co-authors

Kalem works on the files of a project, so a project shared through Git is edited as it is: an Overleaf project cloned with Overleaf's Git integration (git clone https://git.overleaf.com/…, on the plans that include it) or a repository on GitHub that co-authors use, edited in Kalem, built on this computer, and pushed back.

  • Only what you change changes. Kalem keeps every byte it was not asked to change (line endings, spaces, comments, the order of the preamble), so a co-author's diff shows your edits and nothing else.
  • Files that change on disk while open (after git pull, or a co-author's edit synced) are read again; a file you have changed too asks which version to keep.
  • The root document: Overleaf's "main document" setting is not in the files, so Kalem finds the root from them (The root document); a % !TEX root = main.tex line in a chapter file names it for every editor.
  • The engine: Overleaf builds with pdfLaTeX unless the project's menu says otherwise. A % !TEX program = xelatex line, or the setting latex.engine, makes Kalem's build use the same engine, so the PDF matches the one co-authors see.
  • Build outputs: Ignore Build Outputs in Git adds what LaTeX writes beside the document (*.aux, *.log, *.synctex.gz, …, the root's PDF and latex.output_directory) to the repository's .gitignore, so they are not pushed; a build in a repository without them offers it.

6. BibTeX files

A .bib file opens as a grid: each entry one row with its key, type, authors, title and year, and the entry at the cursor as its source. The BibTeX menu (the palette in the terminal) sorts the rows by author, year, title or key without changing the file (File Order goes back), adds an entry (New Entry) and sets a field of the entry at the cursor (Set Field; an empty value removes it), writing only what changes.