Skip to content

Feature Request: b:vimtex with package and documentclass options at load-time #3180

@kiryph

Description

@kiryph

Is your feature request related to a problem? Please describe it.
I want to create a LuaSnip snippet which takes into account package and documentclass options as given at load-time.

This is similar to the functionality of the completion in TeXstudio using .cwl files with #ifOption:<option> as described here: https://texstudio-org.github.io/background.html#description-of-the-cwl-format

Describe the solution you'd like
The buffer-local variable b:vimtex should also have documentclass and package options of the current document. So the document parser and related methods like VimTeXInfo must be extended.

Afaik, there are two types of options, key-only or key=value and they can be written on a single line or on multiple lines. But they are always enclosed between square brackets between documentclass/usepackage/requirepackage and {name}.

Example file

\RequirePackage[debrief]{silence}
\documentclass[draft]{article}

\usepackage[rgb]{graphicx}
\usepackage[bibencoding=utf8]{biblatex} 

\begin{document}

\end{document}

For the packages :lua vim.print(vim.b.vimtex.packages) could give something like

{
  biblatex = { bibencoding = 'utf8' },
  graphicx = { rgb = nil },
  keyval = vim.empty_dict(),
}

I know that many packages have additional setup commands which are often equivalent to package options. Examples are

\KOMAoptions{} % koma documentclasses scrbook, scrarticle, ...
\hypersetup{options} % package hyperref
\mmzset{options} % package memoize
\captionsetup{options} % package caption (uses one level of nested options)
% ...

I consider this outside the scope of this feature request.
Many package and documentclass options are given directly and sometimes are even required on load time (see e.g. biblatex). So this is already helpful. But this can mean the option could be altered after loading the package and hence the state depends on the line in the tex file.

Describe alternatives you've considered
None that I am aware of.

Extended example
\documentclass[% Options of scrbook
  %
  % Preamble fold starts here, unless 'documentclass' is added to the
  % g:vimtex_fold_commands option.
  %
  % draft,
  fontsize=12pt,
  %smallheadings,
  headings=big,
  english,
  paper=a4,
  twoside,
  open=right,
  DIV=14,
  BCOR=20mm,
  headinclude=false,
  footinclude=false,
  mpinclude=false,
  pagesize,
  titlepage,
  parskip=half,
  headsepline,
  chapterprefix=false,
  appendixprefix=Appendix,
  appendixwithprefixline=true,
  bibliography=totoc,
  toc=graduated,
  numbers=noenddot,
]{scrbook}

\usepackage[acronyms]{glossaries}
\usepackage[record,style=long]{glossaries-extra}

\usepackage[notes, useibid]{biblatex-chicago}

\usepackage[
  backend=biber,
  style=numeric-comp,
  maxcitenames=99,
  doi=false,
  url=false,
  giveninits=true,
]{biblatex}

\usepackage[english]{babel}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions