update extensions

This commit is contained in:
Meik Hellmund 2024-05-14 00:11:21 +02:00
parent c024532262
commit aa4af0c42a
6 changed files with 116 additions and 9 deletions

View File

@ -15,3 +15,7 @@ contributes:
pdf: pdf:
include-in-header: include-in-header:
- "resources/tex/juliainc.tex" - "resources/tex/juliainc.tex"
typst:
include-in-header:
- "resources/typst/juliainc.typ"

View File

@ -118,6 +118,55 @@ local function LaTeXconverter(fg, bg, bold, light, italic, underline, inverse)
return starttag, endtag return starttag, endtag
end end
local function Typstconverter(fg, bg, bold, light, italic, underline, inverse)
local starttag = "raw(\""
local endtag = "\")"
if inverse then
fg, bg = bg, fg
end
if underline then
starttag = "show: c => underline(c);" .. starttag
end
if type(bg) == "number" then
starttag = "show: c => invertbox(" .. ANSI_COLORS[bg+1] .. ",c);" .. starttag
elseif type(bg) == "table" then
starttag = string.format("show: c => invertbox(rgb(%d,%d,%d),c);", bg[1], bg[2], bg[3]) .. starttag
elseif inverse then
starttag = "show: c => invertbox(ansi-default-inverse-bg ,c);" .. starttag
end
if type(fg) == "number" then
starttag = "set text(fill:" .. ANSI_COLORS[fg+1] ..");" .. starttag
elseif type(fg) == "table" then
starttag = string.format("set text(fill:rgb(%d,%d,%d));", fg[1], fg[2], fg[3]) .. starttag
elseif inverse then
starttag = "set text(fill: ansi-default-inverse-fg);" .. starttag
end
if italic then
starttag = "set text(style:\"italic\");" .. starttag
end
if bold then
starttag = "set text(weight:\"bold\");" .. starttag
end
if light then
starttag = "set text(weight:\"light\");" .. starttag
end
return "#{" .. starttag, endtag.."}"
end
local function HTMLconverter(fg, bg, bold, light, italic, underline, inverse) local function HTMLconverter(fg, bg, bold, light, italic, underline, inverse)
if not (fg or bg or bold or light or italic or underline or inverse) then if not (fg or bg or bold or light or italic or underline or inverse) then
return "","" return "",""
@ -184,6 +233,9 @@ local function codeBlockTrans(e)
elseif quarto.doc.isFormat('html') then elseif quarto.doc.isFormat('html') then
converter = HTMLconverter converter = HTMLconverter
fmt = 'html' fmt = 'html'
elseif quarto.doc.isFormat('typst') then
converter = Typstconverter
fmt = 'typst'
else else
return return
end end
@ -316,6 +368,10 @@ local function codeBlockTrans(e)
if fmt == 'latex' then if fmt == 'latex' then
return pandoc.RawBlock(fmt, [[\begin{]]..texenv.."}\n"..out.."\n"..[[\end{]].. texenv .. "}") return pandoc.RawBlock(fmt, [[\begin{]]..texenv.."}\n"..out.."\n"..[[\end{]].. texenv .. "}")
end end
if fmt == 'typst' then
return pandoc.RawBlock(fmt, "#"..texenv.."[\n"..out.."\n]")
end
end end

View File

@ -0,0 +1,31 @@
#show raw: set text(font: "JuliaMono")
// define cell layout
#let OutputCell = block.with(width:100%, inset: 5pt)
#let AnsiOutputCell = block.with(width: 100%, inset: 5pt)
#let StderrOutputCell = block.with(width: 100%, stroke: 1pt + red, inset: 5pt)
//#set highlight(top-edge: "ascender", bottom-edge: "descender")
#let invertbox(color, c) = box(outset: (x: 0.05em, y: 0.25em), fill: color, c)
//https://github.com/typst/typst/discussions/3057q
#let ansi-black = rgb("#3E424D")
#let ansi-black-intense = rgb("#282C36")
#let ansi-red = rgb("#E75C58")
#let ansi-red-intense = rgb("#B22B31")
#let ansi-green = rgb("#00A250")
#let ansi-green-intense = rgb("#007427")
#let ansi-yellow = rgb("#DDB62B")
#let ansi-yellow-intense = rgb("#B27D12")
#let ansi-blue = rgb("#208FFB")
#let ansi-blue-intense = rgb("#0065CA")
#let ansi-magenta = rgb("#D160C4")
#let ansi-magenta-intense = rgb("#A03196")
#let ansi-cyan = rgb("#60C6C8")
#let ansi-cyan-intense = rgb("#258F8F")
#let ansi-white = rgb("#C5C1B4")
#let ansi-white-intense = rgb("#A1A6B2")
#let ansi-default-inverse-fg = rgb("#FFFFFF")
#let ansi-default-inverse-bg = rgb("#000000")

View File

@ -1,7 +1,7 @@
title: LaTeX Environment title: LaTeX Environment
author: RStudio, PBC author: Posit Software, PBC
version: 1.1.1 version: 1.2.1
quarto-required: ">=1.2.198" quarto-required: ">=1.3"
contributes: contributes:
filters: filters:
- latex-environment.lua - latex-environment.lua

View File

@ -97,6 +97,17 @@ local function writeEnvironments(divEl)
end end
end end
local function buildCommandArgs(opts, format)
local function wrap(o)
return string.format(format, o)
end
local t = pandoc.List()
for str in string.gmatch(opts, "([^"..",".."]+)") do
t:insert(str)
end
return table.concat(t:map(wrap), "")
end
-- use the environments from metadata to -- use the environments from metadata to
-- emit a custom environment for latex -- emit a custom environment for latex
local function writeCommands(spanEl) local function writeCommands(spanEl)
@ -105,19 +116,25 @@ local function writeCommands(spanEl)
if spanEl.attr.classes:includes(k) then if spanEl.attr.classes:includes(k) then
-- resolve the begin command -- resolve the begin command
local beginCommand = pandoc.RawInline('latex', '\\' .. pandoc.utils.stringify(v) .. '{') local beginCommand = '\\' .. pandoc.utils.stringify(v)
local opts = spanEl.attr.attributes['options'] local opts = spanEl.attr.attributes['options']
local args = spanEl.attr.attributes['arguments']
if opts then if opts then
beginCommand = pandoc.RawInline('latex', '\\' .. pandoc.utils.stringify(v) .. '[' .. opts .. ']{') beginCommand = beginCommand .. buildCommandArgs(opts, "[%s]")
end
if args then
beginCommand = beginCommand .. buildCommandArgs(args, "{%s}")
end end
local beginCommandRaw = pandoc.RawInline('latex', beginCommand .. '{')
-- the end command -- the end command
local endCommand = pandoc.RawInline('latex', '}') local endCommandRaw = pandoc.RawInline('latex', '}')
-- attach the raw inlines to the span contents -- attach the raw inlines to the span contents
local result = spanEl.content local result = spanEl.content
table.insert(result, 1, beginCommand) table.insert(result, 1, beginCommandRaw)
table.insert(result, endCommand) table.insert(result, endCommandRaw)
return result return result
end end

View File

@ -26,7 +26,6 @@ Es ist vollständig in Julia geschrieben und bietet als _backends_ `Cairo` (Vekt
- [Beautiful Makie](https://beautiful.makie.org/) - eine Seite mit vielen Beispielen - [Beautiful Makie](https://beautiful.makie.org/) - eine Seite mit vielen Beispielen
## Einbindung anderer Grafikbibliotheken ## Einbindung anderer Grafikbibliotheken