mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-03 10:22:43 +00:00
feat(image): make math packages configurable. Closes #1295
This commit is contained in:
parent
aaed4a9411
commit
e27ba726b1
4 changed files with 20 additions and 3 deletions
|
@ -40,7 +40,8 @@ M.transforms = {
|
||||||
if not content:find("^\\begin") then
|
if not content:find("^\\begin") then
|
||||||
content = ("\\[%s\\]"):format(content)
|
content = ("\\[%s\\]"):format(content)
|
||||||
end
|
end
|
||||||
local packages = { "xcolor", "amsmath", "amssymb" }
|
local packages = { "xcolor" }
|
||||||
|
vim.list_extend(packages, Snacks.image.config.convert.math.packages)
|
||||||
for _, line in ipairs(vim.api.nvim_buf_get_lines(ctx.buf, 0, -1, false)) do
|
for _, line in ipairs(vim.api.nvim_buf_get_lines(ctx.buf, 0, -1, false)) do
|
||||||
if line:find("\\usepackage") then
|
if line:find("\\usepackage") then
|
||||||
for _, p in ipairs(vim.split(line:match("{(.-)}") or "", ",%s*")) do
|
for _, p in ipairs(vim.split(line:match("{(.-)}") or "", ",%s*")) do
|
||||||
|
|
|
@ -103,6 +103,11 @@ local defaults = {
|
||||||
---@class snacks.image.convert.Config
|
---@class snacks.image.convert.Config
|
||||||
convert = {
|
convert = {
|
||||||
notify = true, -- show a notification on error
|
notify = true, -- show a notification on error
|
||||||
|
math = {
|
||||||
|
-- for latex documents, the doc packages are included automatically,
|
||||||
|
-- but you can add more packages here. Useful for markdown documents.
|
||||||
|
packages = { "amsmath", "amssymb", "amsfonts", "amscd", "mathtools", "physics", "siunitx", "mhchem" },
|
||||||
|
},
|
||||||
---@type snacks.image.args
|
---@type snacks.image.args
|
||||||
mermaid = function()
|
mermaid = function()
|
||||||
local theme = vim.o.background == "light" and "neutral" or "dark"
|
local theme = vim.o.background == "light" and "neutral" or "dark"
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
\usepackage{graphicx} % For images
|
\usepackage{graphicx} % For images
|
||||||
\usepackage{amsmath} % For math symbols
|
\usepackage{amsmath} % For math symbols
|
||||||
\usepackage{amssymb} % For extra math symbols
|
\usepackage{amssymb} % For extra math symbols
|
||||||
|
\usepackage{multirow} % For extra math symbols
|
||||||
|
|
||||||
\begin{document}
|
\begin{document}
|
||||||
|
|
||||||
|
@ -20,8 +21,17 @@ Inline image:
|
||||||
|
|
||||||
\newpage
|
\newpage
|
||||||
|
|
||||||
|
|
||||||
\section{Math Tests}
|
\section{Math Tests}
|
||||||
|
|
||||||
|
|
||||||
|
$
|
||||||
|
cases(
|
||||||
|
E_x = E_0 e^(j omega t - y z),
|
||||||
|
H_y = gamma / (j omega mu_0) E_x = eta^e E_0 e^(j omega - y z) = H_0 e^(j omega t - y z)
|
||||||
|
)
|
||||||
|
$
|
||||||
|
|
||||||
Inline math: \(E=mc^2$ and $\int_0^1 x^2 \,dx\)
|
Inline math: \(E=mc^2$ and $\int_0^1 x^2 \,dx\)
|
||||||
|
|
||||||
Inline math: $E=mc^2$ and $\int_0^1 x^2 \,dx$
|
Inline math: $E=mc^2$ and $\int_0^1 x^2 \,dx$
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#set text(size: 12pt, fill: rgb("#FF0000"))
|
#set text(size: 12pt, fill: rgb("#FF0000"))
|
||||||
$ 5 + 5 = 10 $
|
$ 5 + 5 = 10 $
|
||||||
|
|
||||||
$ E = m c^2 $
|
$ E = g c^2 $
|
||||||
|
|
||||||
$ A = pi r^2 $
|
$ A = pi r^2 $
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ $ cal(A) :=
|
||||||
|
|
||||||
{ x in RR | x "is natural" } $
|
{ x in RR | x "is natural" } $
|
||||||
#let x = 5
|
#let x = 5
|
||||||
$ #x < 17 $
|
|
||||||
|
$ x < 17 $
|
||||||
|
|
||||||
$ (3x + y) / 7 &= 9 && "given" \
|
$ (3x + y) / 7 &= 9 && "given" \
|
||||||
3x + y &= 63 & "multiply by 7" \
|
3x + y &= 63 & "multiply by 7" \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue