Skip to content

Al3cLee/nvim

Repository files navigation

nvim

My NeoVim setup folder. I use LazyVim with the WezTerm terminal emulator.

Requirements

  • C language and make
  • The requirements of NeoVim
  • The requirements of LazyVim
  • npm
  • Any language you want to use
  • The Euler Math and Lato fonts discoverable by typst

Wrapping

There is an autocmd set up by lazyvim (search for wrap_spell in this webpage to find it under the tab Default Auto Commands) which wraps lines in text files; I have line wrap disabled by default, and wrapping can also be toggled via keyboard shortcut <space>uw.

Julia Language Server

The Julia language server is provided by JETLS.jl, see the docs for details about setup. For configuration to work, the root_markder field needs to be specified in the Neovim setup of JETLS.

Typst templates

Note

This is still work-in-progress, comments are welcome!

The file templates/typst_templates.typ implements a Typst template file that allows

  • freely switching between touying and a regular document,
  • stand-alone compiling of child files, and
  • correct bibliography for both child files and the main file.

Tip

To initiate a multi-file typst project, use the vim command :TypstDoc for document and :TypstTouying for touying slides. The project will be initiated in ./typst_doc and ./typst_touying, respectively. To populate the current directory with the template files, use the command :TypstTemplate.

The main difficulty was to avoid multiple-bibliography conflict while still suppressing missing-citation warnings in child files. This was achieved under the guidance provided in this forum post. Note, however, that the function load-bib provided there needs a small change; see my typst_templates.typ for details. The counter for bibs should not update itself, so I removed the condition counter("bibs").get().first() == 1.

The mental model is that, in a project,

  • the preamble.typ file stores functions and templates to map contents to formatted output,
  • some child.typ files store contents, and
  • the main.typ file collects various child files together via #include.

Specifically,

  • the main file's show rules should be minimal; at least, they should be orthogonal to those in child files, and
  • the semantic mark of an atomic note is a 1st level heading.

I implemented the (very opinionated) approach where each child file can be compiled stand-alone without errors, and look exactly the same as the main file (except for the numberings, of course). This approach is motivated by my enthusiasm to atomize my notes: I try to write short notes and then combine them when I need to. For reasons why this is beneficial, see this page: Atomic Notes.

The setup for regular documents and touying files are slightly different. This is because: in a child file, setting show rules related to page size causes page breaks in the main document, but I don't necessarily want page breaks between child files, while in touying documents, page breaks are just new slides, which are acceptable. Therefore, I set the page size and numberings in the main file for regular documents, while touying documents have main files that do not show anything.


Below is a minimum working example for regular documents. Each file needs to import the preamble and specify a show rule. For bibliography integration, an additional show rule is needed.

When a child file only contains one 1st-level heading, numbering equations and proclamation-like environments like 1.x becomes unnecessary. The file preamble_standalone implements a template that numbers everything continuously without base-ing them on headings. This could be useful if you want to compile a child file only and distribute it.

// preamble.typ
// This should be exactly the same as
// templates/typst_templates.typ.
// You can use the vim command :TypstTemplate
// to paste that file if you use this setup.
// main.typ
#import "preamble.typ": *
#show: template-doc-main.with(doctitle: Title) // Set title here
#show: bib-main-doc // Use this line if you have bibliography

#include "child.typ"
// child.typ
#import "preamble.typ": *
// #import "preamble_standalone.typ": *
// Use the above line if you want your child file
// look like a standalone document;
// remember to comment out the import of preamble.typ
// in that case.
#show: template-doc
#show: bib-child

#lorem(30) // Random text

For touying files, a minimal setup is

// preamble.typ
// This is the same as
// templates/typst_templates.typ
// main.typ
#import "preamble.typ": *
// This import is just for safety

#include "cover.typ"
#include "child_slide.typ"
#include "bib_slide.typ"
// cover.typ
#import "preamble.typ": *
#show: template-touying

#title-slide()
// child_slide.typ
#import "preamble.typ": *
#show: template-touying
#show: bib-child

= Section Title
// bib_slide.typ
#import "preamble.typ": *
#show: template-touying
#show: bib-child // Actually, this line is not necessary

#bib-slide()

It is strongly advised to keep all contents in child files in this multiple-file setup. For touying this structure does not allow contents in main.typ; for doc you can #show: template-doc in main.typ and write contents.

For calligraphic letters (typeset with math.cal) I use the Euler Math font. This font is designed by Hermann Zapf, who also created Palatino and Optima. Previously this font was primarily a LaTeX package, but it now has a modern version and is actively maintained! See https://ctan.org/pkg/euler-math . To use it, simply write

#let cal(body) = text(font: "Euler Math", math.cal(body))

One can also define custom symbols via

#let empty = [#text(font: "Euler Math", [\u{ea7b}])]

LuaSnip

In lua/typst_math.lua I defined a module that uses treesitter parsing tools to determine whether the cursor is inside a typst math environment, thus enabling math-only snippets (see LuaSnip/typst.lua ).

A similar treatment is applied to Markdown files in lua/markdown_math.lua and LuaSnip/markdown.lua.

About

My NeoVim setup

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors