diff --git a/_extensions/MHellmund/julia-color/_extension.yml b/_extensions/MHellmund/julia-color/_extension.yml new file mode 100644 index 0000000..b264a63 --- /dev/null +++ b/_extensions/MHellmund/julia-color/_extension.yml @@ -0,0 +1,17 @@ +title: Julia-color +author: Meik Hellmund +version: 1.0.0 +quarto-required: ">=99.9.0" +contributes: + formats: + common: + filters: + - "ansi2htmltex.lua" + html: + monofont: "JuliaMono" + css: + - "resources/css/ansicolor.css" + - "resources/css/juliamono.css" + pdf: + include-in-header: + - "resources/tex/juliainc.tex" diff --git a/_extensions/julia/ansi2htmltex.lua b/_extensions/MHellmund/julia-color/ansi2htmltex.lua similarity index 74% rename from _extensions/julia/ansi2htmltex.lua rename to _extensions/MHellmund/julia-color/ansi2htmltex.lua index 6615353..8e41bce 100644 --- a/_extensions/julia/ansi2htmltex.lua +++ b/_extensions/MHellmund/julia-color/ansi2htmltex.lua @@ -1,10 +1,5 @@ --- this is essentially +-- based on -- https://github.com/jupyter/nbconvert/blob/main/nbconvert/filters/ansi.py --- converted to lua - --- good list of ANSI escape sequences: --- https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 - local ANSI_COLORS = { "ansi-black", @@ -60,18 +55,8 @@ local function get_extended_color(numbers) return {r, g, b} end - ---[=[ -local re = require "re" - -local ANSI = re.compile [[ - '\x1b%[' {.*?} {[@-~]} - ]] - ---]=] - -local function LaTeXconverter(fg, bg, bold, underline, inverse) - if not (fg or bg or bold or underline or inverse) then +local function LaTeXconverter(fg, bg, bold, light, italic, underline, inverse) + if not (fg or bg or bold or light or italic or underline or inverse) then return "","" end @@ -116,6 +101,16 @@ local function LaTeXconverter(fg, bg, bold, underline, inverse) endtag = "}" .. endtag end + if light then + starttag = starttag .. [[\textlight{]] + endtag = "}" .. endtag + end + + if italic then + starttag = starttag .. [[\textit{]] + endtag = "}" .. endtag + end + if underline then starttag = starttag .. [[\underline{]] endtag = "}" .. endtag @@ -123,8 +118,8 @@ local function LaTeXconverter(fg, bg, bold, underline, inverse) return starttag, endtag end -local function HTMLconverter(fg, bg, bold, underline, inverse) - if not (fg or bg or bold or underline or inverse) then +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 return "","" end local classes = {} @@ -156,6 +151,14 @@ local function HTMLconverter(fg, bg, bold, underline, inverse) table.insert(classes, "ansi-bold") end + if light then + table.insert(classes, "ansi-light") + end + + if italic then + table.insert(classes, "ansi-italic") + end + if underline then table.insert(classes, "ansi-underline") end @@ -196,7 +199,8 @@ local function codeBlockTrans(e) local texenv="OutputCell" local codeclass="" - if string.find(e.text, "\u{a35f}\u{2983}") then + -- if string.find(e.text, "\u{a35f}\u{2983}") then + if string.find(e.text, "\x1b%[") then texenv = "AnsiOutputCell" codeclass = "ansi" end @@ -206,12 +210,18 @@ local function codeBlockTrans(e) end local out="" - -- if string.find(e.text, "\x1b%[") then - if string.find(e.text, "\u{a35f}\u{2983}") then + local text = e.text + + -- we remove links (eg in julia ParseErrors. THey link to local files, so they are useless anyway) + text = text:gsub("\x1b%]8;.-\x1b\\", "") + + if string.find(text, "\x1b%[") then + -- if string.find(text, "\u{a35f}\u{2983}") then local bold = false + local light = false + local italic = false local underline = false local inverse = false - local text = e.text local chunk = "" local fg = nil local bg = nil @@ -221,8 +231,9 @@ local function codeBlockTrans(e) while text ~= "" do numbers = {} - -- local s1, e1, c1, d1 = string.find(text, "\x1b%[(.-)([@-~])") - local s1, e1, c1, d1 = string.find(text, "\u{a35f}\u{2983}(.-)([@-~])") + -- [@-~]: matches single char between 64 and 126 + local s1, e1, c1, d1 = string.find(text, "\x1b%[(.-)([@-~])") + -- local s1, e1, c1, d1 = string.find(text, "\u{a35f}\u{2983}(.-)([@-~])") if s1 then if d1 == "m" then for i in string.gmatch(c1, "([^;]*)") do @@ -238,9 +249,9 @@ local function codeBlockTrans(e) if chunk ~= "" then if bold and type(fg)=="number" and fg<8 then - starttag, endtag = converter(fg+8, bg, bold, underline, inverse) + starttag, endtag = converter(fg+8, bg, bold, light, italic, underline, inverse) else - starttag, endtag = converter(fg, bg, bold, underline, inverse) + starttag, endtag = converter(fg, bg, bold, light, italic, underline, inverse) end out = out .. starttag .. chunk .. endtag end @@ -253,20 +264,26 @@ local function codeBlockTrans(e) bold = false inverse = false underline = false - elseif n == 1 then + elseif n == 1 or n == 5 or n == 6 then -- bold and blink bold = true + elseif n == 2 or n == 8 then -- 'dim' and 'hide' + light = true + elseif n == 3 then + italic = true elseif n == 4 then underline = true - elseif n == 5 then - bold = true -- 'blinking' elseif n == 7 then inverse = true - elseif n == 21 or n == 22 then + elseif n == 21 or n == 22 or n == 25 then bold = false + elseif n == 23 then + italic = false elseif n == 24 then underline = false elseif n == 27 then inverse = false + elseif n == 22 or n == 28 then + light = false elseif n >= 30 and n <= 37 then fg = n - 30 elseif n == 38 then @@ -290,7 +307,7 @@ local function codeBlockTrans(e) end end else - out = e.text + out = text end if fmt == 'html' then return pandoc.RawBlock(fmt, @@ -324,67 +341,13 @@ local function divCodeBlockNoHeader1(e) for i, el in pairs(c) do if el.t == 'Header' then el.level = 6 - -- elneu = pandoc.Para(el.content) - -- c[i] = elneu - end - if el.t == 'CodeBlock' then - if el.classes:includes("jldoctest") then - x,i = el.classes:find("jldoctest") - el.classes:remove(i) - end end end return e end --- test if two divs should be merged -local function testmerge(d1, d2) - return d1 and d1.t == "Div" and d1.classes:includes("cell-output") and #d1.content == 1 - and d2 and d2.t == "Div" and d2.classes:includes("cell-output") and #d2.content == 1 - and d1.content[1].t == "CodeBlock" and not d1.classes:includes("cell-output-stderr") - and d2.content[1].t == "CodeBlock" and not d2.classes:includes("cell-output-stderr") -end - --- merge (div (codecell (text1)), div (codecell(text2))) to div(codecell(text1+text2)) -local function blockMerge(es) - local nl = "" - for i = #es-1, 1, -1 do - if testmerge(es[i], es[i+1]) then - str1 = es[i].content[1].text - str2 = es[i+1].content[1].text - nl = "\n" - if es[i].classes:includes("cell-output-stdout") and es[i+1].classes:includes("cell-output-stdout") then - if str1:sub(-1) == "\n" then - nl = "" - end - if str2:sub(1, 1) == "\n" then - nl = "" - end - end - es[i].content[1].text = str1 .. nl .. str2 - es:remove(i+1) - end - end - return es -end - -local function metaAdd(meta) - --for key, val in pairs(PANDOC_READER_OPTIONS) do - -- quarto.log.warning(key, val) - --end - quarto.doc.addHtmlDependency({name='ansicolors', - stylesheets = {'resources/css/ansicolor.css'}}) - quarto.doc.addHtmlDependency({name='juliamonofont', - stylesheets = {'resources/css/juliamono.css'}}) - if quarto.doc.isFormat('latex') then - quarto.doc.include_file("in-header", "resources/juliainc.tex") - end -end - return { {Div = divStderr}, {Div = divCodeBlockNoHeader1}, - {Blocks = blockMerge}, {CodeBlock = codeBlockTrans}, - {Meta = metaAdd} } diff --git a/_extensions/julia/resources/css/ansicolor.css b/_extensions/MHellmund/julia-color/resources/css/ansicolor.css similarity index 94% rename from _extensions/julia/resources/css/ansicolor.css rename to _extensions/MHellmund/julia-color/resources/css/ansicolor.css index 9aea6a7..b8c5cf1 100644 --- a/_extensions/julia/resources/css/ansicolor.css +++ b/_extensions/MHellmund/julia-color/resources/css/ansicolor.css @@ -1,7 +1,6 @@ /* CSS added by ANSI escape sequences filter */ .ansi { - /* line-height:1.15; */ overflow:auto; } @@ -46,5 +45,8 @@ pre .ansi-cyan-intense-bg { background-color: #258f8f; } pre .ansi-white-intense-bg { background-color: #a1a6b2; } pre .ansi-default-inverse-fg { color: rgba(255, 255, 255, 1); } pre .ansi-default-inverse-bg { background-color: #111111; } -pre .ansi-bold { font-weight: bold; } +pre .ansi-bold { font-weight: 800; } +pre .ansi-light { font-weight: 300; } +pre .ansi-italic { font-style: italic; } pre .ansi-underline { text-decoration: underline; } + diff --git a/_extensions/MHellmund/julia-color/resources/css/juliamono.css b/_extensions/MHellmund/julia-color/resources/css/juliamono.css new file mode 100644 index 0000000..b3f461c --- /dev/null +++ b/_extensions/MHellmund/julia-color/resources/css/juliamono.css @@ -0,0 +1,110 @@ +@font-face { + font-family: JuliaMono; + font-weight: 300; + font-style: normal; + src: url("../fonts/JuliaMono-Light.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 400; + font-style: normal; + src: url("../fonts/JuliaMono-Regular.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 500; + font-style: normal; + src: url("../fonts/JuliaMono-Medium.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 600; + font-style: normal; + src: url("../fonts/JuliaMono-SemiBold.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 700; + font-style: normal; + src: url("../fonts/JuliaMono-Bold.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 800; + font-style: normal; + src: url("../fonts/JuliaMono-ExtraBold.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 900; + font-style: normal; + src: url("../fonts/JuliaMono-Black.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} +@font-face { + font-family: JuliaMono; + font-weight: 300; + font-style: italic; + src: url("../fonts/JuliaMono-LightItalic.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 400; + font-style: italic; + src: url("../fonts/JuliaMono-RegularItalic.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 500; + font-style: italic; + src: url("../fonts/JuliaMono-MediumItalic.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 600; + font-style: italic; + src: url("../fonts/JuliaMono-SemiBoldItalic.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 700; + font-style: italic; + src: url("../fonts/JuliaMono-BoldItalic.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 800; + font-style: italic; + src: url("../fonts/JuliaMono-ExtraBoldItalic.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} + +@font-face { + font-family: JuliaMono; + font-weight: 900; + font-style: italic; + src: url("../fonts/JuliaMono-BlackItalic.woff2") format("woff2"); + text-rendering: optimizeLegibility; +} diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Black.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Black.woff2 new file mode 100644 index 0000000..f8774e0 Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Black.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-BlackItalic.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-BlackItalic.woff2 new file mode 100644 index 0000000..0d10c1d Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-BlackItalic.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Bold.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Bold.woff2 new file mode 100644 index 0000000..032628a Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Bold.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-BoldItalic.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-BoldItalic.woff2 new file mode 100644 index 0000000..e2372ca Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-BoldItalic.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-ExtraBold.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-ExtraBold.woff2 new file mode 100644 index 0000000..ed1ebcc Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-ExtraBold.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-ExtraBoldItalic.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-ExtraBoldItalic.woff2 new file mode 100644 index 0000000..a19a9f1 Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-ExtraBoldItalic.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Light.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Light.woff2 new file mode 100644 index 0000000..f9793ad Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Light.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-LightItalic.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-LightItalic.woff2 new file mode 100644 index 0000000..1e956e2 Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-LightItalic.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Medium.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Medium.woff2 new file mode 100644 index 0000000..24f8482 Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Medium.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-MediumItalic.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-MediumItalic.woff2 new file mode 100644 index 0000000..761ce8d Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-MediumItalic.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Regular.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Regular.woff2 new file mode 100644 index 0000000..1b28da3 Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-Regular.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-RegularItalic.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-RegularItalic.woff2 new file mode 100644 index 0000000..2a79061 Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-RegularItalic.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-SemiBold.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-SemiBold.woff2 new file mode 100644 index 0000000..b11a229 Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-SemiBold.woff2 differ diff --git a/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-SemiBoldItalic.woff2 b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-SemiBoldItalic.woff2 new file mode 100644 index 0000000..3638f74 Binary files /dev/null and b/_extensions/MHellmund/julia-color/resources/fonts/JuliaMono-SemiBoldItalic.woff2 differ diff --git a/_extensions/julia/resources/fonts/LICENSE b/_extensions/MHellmund/julia-color/resources/fonts/LICENSE similarity index 100% rename from _extensions/julia/resources/fonts/LICENSE rename to _extensions/MHellmund/julia-color/resources/fonts/LICENSE diff --git a/_extensions/julia/resources/juliainc.tex b/_extensions/MHellmund/julia-color/resources/tex/juliainc.tex similarity index 84% rename from _extensions/julia/resources/juliainc.tex rename to _extensions/MHellmund/julia-color/resources/tex/juliainc.tex index 836ef19..8a7e193 100644 --- a/_extensions/julia/resources/juliainc.tex +++ b/_extensions/MHellmund/julia-color/resources/tex/juliainc.tex @@ -8,9 +8,15 @@ BoldFont = *-Bold, ItalicFont = *-RegularItalic, BoldItalicFont = *-BoldItalic, + FontFace={l}{n}{Font=*-Light}, + FontFace={l}{it}{Font=*-LightItalic}, Contextuals = AlternateOff, ] +\DeclareRobustCommand{\lseries}{\fontseries{l}\selectfont} +\DeclareTextFontCommand{\textlight}{\lseries} + + \DefineVerbatimEnvironment{OutputCell}{Verbatim}% {xleftmargin=1.5em} \DefineVerbatimEnvironment{AnsiOutputCell}{Verbatim}% @@ -35,4 +41,4 @@ \definecolor{ansi-white}{HTML}{C5C1B4} \definecolor{ansi-white-intense}{HTML}{A1A6B2} \definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF} -\definecolor{ansi-default-inverse-bg}{HTML}{000000} \ No newline at end of file +\definecolor{ansi-default-inverse-bg}{HTML}{000000} diff --git a/_extensions/julia/_extension.yml b/_extensions/julia/_extension.yml deleted file mode 100644 index 300fb3c..0000000 --- a/_extensions/julia/_extension.yml +++ /dev/null @@ -1,15 +0,0 @@ -title: Extensions for Julia -author: Meik Hellmund -version: 0.3.0 -contributes: - format: - common: - filters: - - ansi2htmltex.lua - ipynb-filters: - - escfilter.py - pdf: - default - - html: - monofont: "JuliaMono" diff --git a/_extensions/julia/escfilter.py b/_extensions/julia/escfilter.py deleted file mode 100755 index 76e80c4..0000000 --- a/_extensions/julia/escfilter.py +++ /dev/null @@ -1,5 +0,0 @@ -import sys -f = sys.stdin.read() -g = f.replace('\\u001b[','ꍟ⦃').replace('\\u001b]8;;','').replace('\\u001b\\\\','') -sys.stdout.write(g) - diff --git a/_extensions/julia/resources/css/juliamono.css b/_extensions/julia/resources/css/juliamono.css deleted file mode 100644 index 219ad67..0000000 --- a/_extensions/julia/resources/css/juliamono.css +++ /dev/null @@ -1,55 +0,0 @@ -@font-face { - font-family: JuliaMono; - font-weight: 300; - font-style: normal; - src: url("../fonts/JuliaMono-Light.woff2") format("woff2"); - text-rendering: optimizeLegibility; -} - -@font-face { - font-family: JuliaMono; - font-weight: 400; - font-style: normal; - src: url("../fonts/JuliaMono-Regular.woff2") format("woff2"); - text-rendering: optimizeLegibility; -} - -@font-face { - font-family: JuliaMono; - font-weight: 500; - font-style: normal; - src: url("../fonts/JuliaMono-Medium.woff2") format("woff2"); - text-rendering: optimizeLegibility; -} - -@font-face { - font-family: JuliaMono; - font-weight: 600; - font-style: normal; - src: url("../fonts/JuliaMono-SemiBold.woff2") format("woff2"); - text-rendering: optimizeLegibility; -} - -@font-face { - font-family: JuliaMono; - font-weight: 700; - font-style: normal; - src: url("../fonts/JuliaMono-Bold.woff2") format("woff2"); - text-rendering: optimizeLegibility; -} - -@font-face { - font-family: JuliaMono; - font-weight: 800; - font-style: normal; - src: url("../fonts/JuliaMono-ExtraBold.woff2") format("woff2"); - text-rendering: optimizeLegibility; -} - -@font-face { - font-family: JuliaMono; - font-weight: 900; - font-style: normal; - src: url("../fonts/JuliaMono-Black.woff2") format("woff2"); - text-rendering: optimizeLegibility; -} diff --git a/_extensions/julia/resources/fonts/JuliaMono-Black.woff2 b/_extensions/julia/resources/fonts/JuliaMono-Black.woff2 deleted file mode 100644 index 1657ec9..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-Black.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-BlackItalic.woff2 b/_extensions/julia/resources/fonts/JuliaMono-BlackItalic.woff2 deleted file mode 100644 index 49b7297..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-BlackItalic.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-Bold.woff2 b/_extensions/julia/resources/fonts/JuliaMono-Bold.woff2 deleted file mode 100644 index 14e5bf0..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-Bold.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-BoldItalic.woff2 b/_extensions/julia/resources/fonts/JuliaMono-BoldItalic.woff2 deleted file mode 100644 index 5f353c3..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-BoldItalic.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-BoldLatin.woff2 b/_extensions/julia/resources/fonts/JuliaMono-BoldLatin.woff2 deleted file mode 100644 index 9a318b3..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-BoldLatin.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-ExtraBold.woff2 b/_extensions/julia/resources/fonts/JuliaMono-ExtraBold.woff2 deleted file mode 100644 index e261fce..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-ExtraBold.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-ExtraBoldItalic.woff2 b/_extensions/julia/resources/fonts/JuliaMono-ExtraBoldItalic.woff2 deleted file mode 100644 index 0ce6033..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-ExtraBoldItalic.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-Light.woff2 b/_extensions/julia/resources/fonts/JuliaMono-Light.woff2 deleted file mode 100644 index cabf11d..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-Light.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-LightItalic.woff2 b/_extensions/julia/resources/fonts/JuliaMono-LightItalic.woff2 deleted file mode 100644 index 6962305..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-LightItalic.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-Medium.woff2 b/_extensions/julia/resources/fonts/JuliaMono-Medium.woff2 deleted file mode 100644 index 012c65b..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-Medium.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-MediumItalic.woff2 b/_extensions/julia/resources/fonts/JuliaMono-MediumItalic.woff2 deleted file mode 100644 index e71cf07..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-MediumItalic.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-Regular.woff2 b/_extensions/julia/resources/fonts/JuliaMono-Regular.woff2 deleted file mode 100644 index edefef3..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-Regular.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-RegularItalic.woff2 b/_extensions/julia/resources/fonts/JuliaMono-RegularItalic.woff2 deleted file mode 100644 index 325fd33..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-RegularItalic.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-RegularLatin.woff2 b/_extensions/julia/resources/fonts/JuliaMono-RegularLatin.woff2 deleted file mode 100644 index 7ad4199..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-RegularLatin.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-SemiBold.woff2 b/_extensions/julia/resources/fonts/JuliaMono-SemiBold.woff2 deleted file mode 100644 index 00a2052..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-SemiBold.woff2 and /dev/null differ diff --git a/_extensions/julia/resources/fonts/JuliaMono-SemiBoldItalic.woff2 b/_extensions/julia/resources/fonts/JuliaMono-SemiBoldItalic.woff2 deleted file mode 100644 index 94b5e8e..0000000 Binary files a/_extensions/julia/resources/fonts/JuliaMono-SemiBoldItalic.woff2 and /dev/null differ diff --git a/_quarto.yml b/_quarto.yml index 349d0f1..2493df5 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -42,20 +42,22 @@ book: chapters: - index.qmd - chapters/entwicklungsumgebungen.qmd - - chapters/first_contact.qmd - - chapters/Erste_Bsp.qmd + # - chapters/first_contact.qmd + # - chapters/Erste_Bsp.qmd - chapters/syntax.qmd - chapters/5_TricksHelp.qmd - chapters/numerictypes.qmd - chapters/Pi2.qmd - - chapters/types.qmd - - chapters/pcomplex.qmd - - chapters/9_functs.qmd + # - chapters/types.qmd + # - chapters/pcomplex.qmd + # - chapters/9_functs.qmd - chapters/6_ArraysEtcP1.qmd - - chapters/7_ArraysP2.qmd - - chapters/11_LinAlg.qmd - - chapters/10_Strings.qmd - - chapters/14_Plot.qmd + # - chapters/7_ArraysP2.qmd + # - chapters/11_LinAlg.qmd + # - chapters/10_Strings.qmd + # - chapters/14_Plot.qmd + # - chapters/13_IO.qmd + # - chapters/makie.qmd # - chapters/ablaufsteuerung.qmd # - chapters/example.qmd @@ -64,7 +66,7 @@ book: format: - julia-html: + julia-color-html: theme: light: [cosmo, css/light.scss] dark: [superhero, css/dark.scss] @@ -84,9 +86,9 @@ format: body-width: 1150px # 800 margin-width: 250px gutter-width: 1.5em - cap-location: bottom + cap-location: bottom - julia-pdf: + julia-color-pdf: pdf-engine: xelatex papersize: a4 documentclass: scrreprt @@ -120,6 +122,7 @@ execute: eval: true freeze: auto daemon: 3600 + preserve-ansi: true keep-ipynb: true keep-tex: true diff --git a/chapters/13_IO.qmd b/chapters/13_IO.qmd new file mode 100644 index 0000000..1d8760e --- /dev/null +++ b/chapters/13_IO.qmd @@ -0,0 +1,414 @@ +# Ein- und Ausgabe I/O + +zahlreiche Varianten und Funktionen, das Folgende ist eine kleine Auswahl + +## Konsole + +- OS-abhängig; üblicherweise 3 Kanäle _(streams)_: `stdin, stdout, stderr` (Standardinput, -output, -errorkanal) + + + +- Schreiben nach `stdout`: `print()`,`println()`,`printstyled()` +- Schreiben nach `stderr`: `print(strerr,...)`, `println(stderr,...)`, `printstyled(stderr,...)` +- Lesen von `stdin`: `readline()` + +### Umwandeln von Strings in andere Typen: + + - `chomp()` entfernt newline + - `split()` zerlegt in "Wörter" + - `parse()` wandelt in andere Typen um + +### Buffer + +- `write`-Zugriffe werden gebuffert. + + - `flush(stdout)` leert Buffer + + +```julia +# aus dem ersten Beispielprogramm + +function input(prompt = "Eingabe:") + println(prompt) + flush(stdout) + return chomp(readline()) +end + +``` + + +```julia +a = input("Bitte 2 Zahlen eingeben!") +``` + + +```julia +av = split(a) +``` + + +```julia +parse.(Int, av) +``` + + +```{julia} +# Ausgaben auf den Fehlerkanal stderr erscheinen im Jupyter in rot: +@warn "Das @warn-Macro schreibt nach stderr." +println("Hallo!") +println(stderr, "Das sollte nicht passieren!") +``` + +### Einzelne Tastenanschläge einlesen + +- `readline()` u.ä. warten auf den Abschluss der Eingabe durch Drücken der `Enter`-Taste. +- Zum Einlesen einzelner _keystrokes_: + + - [https://stackoverflow.com/questions/56888266/how-to-read-keyboard-inputs-at-every-keystroke-in-julia](https://stackoverflow.com/questions/56888266/how-to-read-keyboard-inputs-at-every-keystroke-in-julia) + - [https://stackoverflow.com/questions/60954235/how-can-i-test-whether-stdin-has-input-available-in-julia](https://stackoverflow.com/questions/60954235/how-can-i-test-whether-stdin-has-input-available-in-julia) + + +## Formatierte Ausgabe mit dem `Printf`-Paket + +Die Macros `@sprintf` und `@printf` sind den gleichnamigen C-Funktionen nachempfunden + +- Formatstring: Normaler String mit Platzhaltern +- Platzhalter haben die Form +``` +%[flags][width][.precision]type +``` + (wobei die Angaben in eckigen Klammern alle optional sind) +- Typen: +``` +%s string +%i integer +%o integer octal (base=8) +%x, %X integer hexadecimal (base=16) with digits 0-9abcdef or 0-9ABCDEF, resp. +%f floatong point number +%e floating point number, scientific representation +%g floating point, uses %f or %e depending on value +``` + +- Flags: +``` +Pluszeichen: rechtsbündig (Standard) +Minuszeichen: linksbündig +Null: mit führenden Nullen +``` + +- Width: +``` +Anzahl der minimal verwendeten Zeichen (wenn nötig, werden auch mehr genommen) +``` + + +Zeit für Beispiele: + + +```julia +using Printf # Paket laden nicht vergessen! +``` + + +```julia +@printf("|%s|", "Hallo") # string mit Platzhalter für String +``` + + +```julia +@printf("|%10s|", "Hallo") # Minimallänge, rechtsbündig +``` + + +```julia +@printf("|%-10s|", "Hallo") # linksbündig +``` + + +```julia +@printf("|%3s|", "Hallo") # Längenangabe kann überschritten werden + # besser eine 'kaputt formatierte' Tabelle als falsche Werte!! +``` + + +```julia +j = 123 +k = 90019001 +l = 3342678 + +@printf("j= %012i, k= %-12i, l = %12i", j, k, l) # 0-Flag für führende Nullen +``` + +`@printf` und `@sprintf` können wie alle Macros wie Funktionen aufgerufen werden: + + +```julia +@printf("%i %i", 22, j) +``` + +-- oder wie Macros, also ohne Funktionsklammern und ohne Komma: + + +```julia +@printf "%i %i" 22 j +``` + +`@printf` kann als erstes Argument noch einen stream übergeben bekommen. + +Ansonsten besteht die Argumentliste aus + +- Formatstring mit Platzhaltern +- Variablen in der Reihenfolge der Platzhalter, in Anzahl und Typ zu den Platzhaltern passend + + +```{julia} +@printf(stderr, "Erstes Resultat: %i %s\nZweites Resultat %i", + j, "(geschätzt)" ,k) +``` + +`@sprintf` druckt nichts, sondern liefert den ausgefüllten formatierten String zurück: + + +```julia +str = @sprintf("x = %10.6f", π ); +``` + + +```julia +str +``` + +##### Formatierung der Gleitkommazahlen: + +Bedeutung des _Precision_-Wertes: + +- `%f` und `%e`-Format: max. Anzahl der Nachkommastellen +- `%g`-Format: max. Anzahl von ausgegebenen Ziffern (Vor- + Nachkommastellen) + + +```julia +x = 123456.7890123456 + +@printf("%20.4f %20.4e", x, x) # 4 Nachkommastellen +``` + + +```julia +@printf("%20.7f %20.7e", x, x) # 7 Nachkommastellen +``` + + +```julia +@printf("%20.7g %20.4g", x, x) # insgesamt 7 bzw. 4 Stellen +``` + +## Dateioperationen + +Dateien werden + + - geöffnet ==> Dabei ensteht ein neues _stream_-Objekt (zusätzlich zu `stdin, stdout, stderr`) + - dann kann dieser _stream_ gelesen und geschrieben werden + - geschlossen ==> _stream_-Objekt wird von Datei getrennt + + ``` + stream = open(path, mode) + ``` + + - path: Dateiname/pfad + - mode: + ``` + "r" read, öffnet am Dateianfang + "w" write, öffnet am Dateianfang (Datei wird neu angelegt oder überschrieben) + "a" append, öffnet zum Weiterschreiben am Dateiende + ``` + + +```julia +f = open("datei.txt", "w") +``` + + +```julia +@printf(f, "%20i\n", k) +``` + + +```julia +println(f, " zweite Zeile") +``` + + +```julia +close(f) +``` + + +```julia +;cat datei.txt +``` + + +```julia +f = open("datei.txt", "r") +``` + + +```julia +n = 0 +for i in readlines(f) # Lese zeilenweise + n += 1 + println(n, i) # Drucke mit Zeilennummer +end +``` + +## Pakete für Dateiformate + +Pakete für die Ein- und Ausgabe in den verschiedensten Dateiformaten + +- [PrettyTables.jl](https://ronisbr.github.io/PrettyTables.jl/stable/) Ausgabe von formatierten Tabellen +- [DelimitedFiles.jl](https://docs.julialang.org/en/v1/stdlib/DelimitedFiles/) Ein- und Ausgabe von Matrizen u.ä. +- [CSV.jl](https://csv.juliadata.org/stable/) Ein- und Ausgabe von Dateien mit "comma-delimited values" u.ä. +- [XLSX.jl](https://felipenoris.github.io/XLSX.jl/stable/tutorial/) Ein- und Ausgabe von Excel-Dateien + +und viele andere mehr... + +### Delimited Files + + + +```julia +using DelimitedFiles +``` + + +```julia +A = rand(200,3) +``` + + +```julia +f = open("data2.txt", "w") +``` + + +```julia +writedlm(f, A) +``` + + +```julia +close(f) +``` + + +```julia +;head data2.txt +``` + + +```julia +B = readdlm("data2.txt") + +``` + + +```julia +# man kann open() auch als 1.Argument eine function(iostream) übergeben, die auf den stream +# angewendet wird, wonach der stream automatisch geschlosssen wird. +# +# Mit der do-Notation sieht obiger code so aus: + +open("data2.txt", "w") do io + writedlm(io, A) +end + +``` + +### CSV und DataFrames + +- [DataFrames.jl](https://dataframes.juliadata.org/stable/) ist ein Paket zum bequemen Umgang mit tabellarischen Daten + + + + +```julia +using CSV, DataFrames, Downloads +``` + + +```julia +# Wetterdaten von Westerland, s. https://dev.meteostat.net/bulk/hourly.html + + +url = "https://bulk.meteostat.net/v2/hourly/10018.csv.gz" +``` + + +```julia +http_response = Downloads.download(url) +``` + + +```julia +file = CSV.File(http_response, header=false) +``` + + +```julia +# https://dev.meteostat.net/bulk/hourly.html#endpoints + +# Spalte 1 Datum +# 2 Uhrzeit (Stunde) +# 3 Temp +# 5 Luftfeuchtigkeit +# 6 Niederschlag +# 8 Windrichtung +# 9 Windstärke + + +df = DataFrame(file) +``` + + +```julia +describe(df) +``` + + +```julia +using StatsPlots +``` + + +```julia +using Dates +``` + + +```julia +# neue Spalte mit Sp.1 und 2 (date & time) kombiniert + +df[!, :datetime] = DateTime.(df.Column1) .+ Hour.(df.Column2); +``` + + +```julia +describe(df) +``` + + +```julia +@df df plot(:datetime, :Column3) +``` + + +```julia +@df df plot(:datetime, [:Column9, :Column6, :Column3], + xlims = (DateTime(2022,1,1), DateTime(2022,7,1)), + layout=(3,1), title=["Wind" "Regen" "Temp"], legend=:none) +``` + + +```julia + +``` diff --git a/chapters/6_ArraysEtcP1.qmd b/chapters/6_ArraysEtcP1.qmd index bb56672..c63df71 100644 --- a/chapters/6_ArraysEtcP1.qmd +++ b/chapters/6_ArraysEtcP1.qmd @@ -1,5 +1,8 @@ -# Container +--- +engine: julia +--- +# Container Julia bietet eine große Auswahl von Containertypen mit weitgehend ähnlichem Interface an. Wir stellen hier `Tuple`, `Range` und `Dict` vor, im nächsten Kapitel dann `Array`, `Vector` und `Matrix`. diff --git a/chapters/Pi2.qmd b/chapters/Pi2.qmd index f324b29..789b91e 100644 --- a/chapters/Pi2.qmd +++ b/chapters/Pi2.qmd @@ -1,18 +1,11 @@ --- -format: - html: - include-in-header: - text: | - +engine: julia --- # Ein Beispiel zur Stabilität von Gleitkommaarithmetik -## Berechnung von $\pi$ nach Archimedes -```{julia} +```julia #| error: false #| echo: false #| output: false @@ -24,44 +17,25 @@ using Base64 ## see https://github.com/JuliaPlots/PlotlyJS.jl/blob/master/src/PlotlyJS.jl ## https://discourse.julialang.org/t/encode-a-plot-to-base64/27765/3 -function IJulia.display_dict(p::PlotlyJS.SyncPlot) - Dict( - # "application/vnd.plotly.v1+json" => JSON.lower(p), - # "text/plain" => sprint(show, "text/plain", p), - "text/html" => let - buf = IOBuffer() - show(buf, MIME("text/html"), p) - #close(buf) - #String(resize!(buf.data, buf.size)) - String(take!(buf)) - end, - "image/png" => let - buf = IOBuffer() - buf64 = Base64EncodePipe(buf) - show(buf64, MIME("image/png"), p) - close(buf64) - #String(resize!(buf.data, buf.size)) - String(take!(buf)) - end, - ) - end - - function Base.show(io::IO, mimetype::MIME"text/html", p::PlotlyJS.SyncPlot) - uuid = string(UUIDs.uuid4()) - show(io,mimetype,@htl(""" -
- -""")) + """)) end ``` + +## Berechnung von $\pi$ nach Archimedes + Eine untere Schranke für $2\pi$, den Umfang des Einheitskreises, erhält man durch die Summe der Seitenlängen eines dem Einheitskreis eingeschriebenen regelmäßigen $n$-Ecks. Die Abbildung links zeigt, wie man beginnend mit einem Viereck der Seitenlänge $s_4=\sqrt{2}$ die Eckenzahl iterativ verdoppelt. @@ -165,8 +139,7 @@ layout = Layout(xaxis_title="Iterationsschritte", yaxis_title="rel. Fehler", plot([scatter(x=is, y=ϵ_A, mode="markers+lines", name="Iteration A", yscale=:log10), scatter(x=is, y=ϵ_B, mode="markers+lines", name="Iteration B", yscale=:log10)], layout) - -``` + ``` diff --git a/chapters/numerictypes.qmd b/chapters/numerictypes.qmd index aa84c03..cc12748 100644 --- a/chapters/numerictypes.qmd +++ b/chapters/numerictypes.qmd @@ -1,7 +1,9 @@ +--- +engine: julia +--- + # Maschinenzahlen - - ```{julia} for x ∈ ( 3, 3.3e4, Int16(20), Float32(3.3e4), UInt16(9) ) @show x sizeof(x) typeof(x) diff --git a/chapters/syntax.qmd b/chapters/syntax.qmd index 9917a22..30477de 100644 --- a/chapters/syntax.qmd +++ b/chapters/syntax.qmd @@ -1,4 +1,6 @@ - +--- +engine: julia +--- # Grundlagen der Syntax @@ -52,6 +54,7 @@ x = log(10) - Im interaktiven Betrieb (REPL oder Notebook) unterdrückt ein Semikolon nach der letzten Anweisung die Ausgabe des Ergebnisses dieser Anweisung. :::{.callout-tip} + ## Beispiel Im interaktiven Betrieb wird der Wert der letzten Anweisung auch ohne explizites `print()` ausgegeben: diff --git a/index.qmd b/index.qmd index 8e35116..f521e9e 100644 --- a/index.qmd +++ b/index.qmd @@ -1,3 +1,6 @@ +--- +engine: julia +--- # Was ist Julia? {.unnumbered} @@ -5,6 +8,16 @@ Julia ist eine noch recht junge für *scientific computing* konzipierte moderne Ein kleines Codebeispiel: +```{julia} +#| error: false +#| echo: false +#| output: false + +using CairoMakie +CairoMakie.activate!(type = "png") +set_theme!(size=(800, 180)) +``` + ```{julia} using CairoMakie a = [3, 7, 5, 3] @@ -20,7 +33,6 @@ end f ``` - ## Geschichte {.unnumbered} - 2009 Beginn der Entwicklung am *Computer Science and Artificial