diff --git a/_extensions/cours/_extension.yml b/_extensions/cours/_extension.yml index 17b0495..bf7f086 100644 --- a/_extensions/cours/_extension.yml +++ b/_extensions/cours/_extension.yml @@ -8,9 +8,10 @@ contributes: pdf-engine: lualatex documentclass: scrartcl template-partials: + - before-title.tex - title.tex + - after-header-includes.latex include-in-header: header.tex - include-before-title: before-title.tex include-before-body: before-body.tex papersize: a4paper geometry: @@ -20,4 +21,9 @@ contributes: - head=14.5pt number-sections: true toc: true + metadata: + type-document: + cours: false + exercice: false + actvite: false diff --git a/_extensions/cours/_extensions/GeorgRamer/si/_extension.yml b/_extensions/cours/_extensions/GeorgRamer/si/_extension.yml new file mode 100644 index 0000000..c93df26 --- /dev/null +++ b/_extensions/cours/_extensions/GeorgRamer/si/_extension.yml @@ -0,0 +1,8 @@ +title: Si +author: Georg Ramer +version: 0.3.0 +quarto-required: ">=1.5.0" +contributes: + shortcodes: + - si.lua + diff --git a/_extensions/cours/_extensions/GeorgRamer/si/si.lua b/_extensions/cours/_extensions/GeorgRamer/si/si.lua new file mode 100644 index 0000000..e6a773a --- /dev/null +++ b/_extensions/cours/_extensions/GeorgRamer/si/si.lua @@ -0,0 +1,169 @@ +si_prefix = {Q = "Q", R = "R", Y = "Y", Z="Z", E = "E", P="P", T="T", G="G", M="M", k="k", h="h", d="d", c="c", m="m", u="\u{03BC}", n="n", p="p", f="f", a="a", z="z", y="y", r="r", q="q"} + +si_units = {m="m", l="l", L="L", g="g", V="V", A="A", ohm="\u{03A9}", ang="\u{212B}"} + +SPACE = "\u{202F}" +TIMES = "\u{00D7}" +DOT = "\u{00B7}" + + +local function concatenateTables(t1, t2) + for i = 1, #t2 do + t1[#t1 + 1] = t2[i] + end + return t1 +end + +function identify_block(arg) + if arg == "." then + return "DOT" + end + + if arg == "x" then + return "TIMES" + end + + + if arg == "/" then + return "SLASH" + end + + if string.match(arg, "^[a-zA-Z_°]+[-0-9]-$") then + + return "UNIT" + end + + num_start = string.match(arg, "^[%d.,Eeij()+-°]+$") + + if num_start then + return "NUMERIC" + end + + + + return nil +end + + +parsers = {} + + + +function parse_numeric(arg) + arg = string.gsub(arg, "%+%-", "\u{00B1}") + -- add exponents + outtab = {} + while string.find(arg, "[eE][+-]?%d+") do + idx_start, idx_stop = string.find(arg, "[eE][+-]?%d+") + before_substr = string.sub(arg, 1, idx_start-1)..TIMES.."10" + table.insert(outtab, before_substr) + table.insert(outtab, pandoc.Superscript(string.sub(arg,idx_start+1,idx_stop))) + arg = string.sub(arg, idx_stop+1) + end + if string.len(arg)>0 then + table.insert(outtab, arg) + end + return outtab +end + +parsers["NUMERIC"] = parse_numeric + +function parse_dot(arg) + + return {DOT} + +end +parsers["DOT"] = parse_dot + +function parse_slash(arg) + + return {"/"} + +end + + +parsers["SLASH"] = parse_slash + + +function parse_times(arg) + return {TIMES} +end + +parsers["TIMES"] = parse_times + + +function parse_unit(arg) + + -- check for exponent and remove + + exponent_start = string.find(arg, "%-?%d+$") + exponent = nil + if exponent_start then + exponent = pandoc.Superscript(string.sub(arg, exponent_start)) + arg = string.sub(arg, 0, exponent_start-1) + end + + -- there may be a subscript in the unit, check and remove + subscript_start = string.find(arg, "_[a-zA-Z%d]+") + + subscript = nil + if subscript_start then + subscript = pandoc.Subscript(string.sub(arg, subscript_start+1)) + arg = string.sub(arg, 0, subscript_start-1) + end + + -- if the remaining part is longer than one character, the first character may be a prefix + prefix=nil + if string.len(arg)>1 then + + if si_prefix[string.sub(arg,0,1)] ~=nil and si_units[arg] == nil then + prefix = si_prefix[string.sub(arg,0,1) ] + arg = string.sub(arg,2) + end + end + -- check whether the remaining part is a shortcut unit and replace + if si_units[arg] ~= nil then + arg = si_units[arg] + end + + -- assemble + outtab = {} + + if prefix then + table.insert(outtab, prefix) + end + table.insert(outtab, arg) + if subscript then + table.insert(outtab, subscript) + end + if exponent then + table.insert(outtab, exponent) + + end + return outtab +end + +parsers["UNIT"] = parse_unit + + +return { + ['si'] = function(args, kwargs, meta) + outtab = {} + for idx, arg in ipairs(args) do + block_type = identify_block(arg) + + if idx>1 then + table.insert(outtab, SPACE) + end + if block_type then + + outtab=concatenateTables(outtab, parsers[block_type](arg)) + else + table.insert(outtab, arg) + end + + end + + return outtab + end +} diff --git a/_extensions/cours/_extensions/quarto-ext/latex-environment/_extension.yml b/_extensions/cours/_extensions/quarto-ext/latex-environment/_extension.yml new file mode 100644 index 0000000..2f55b2f --- /dev/null +++ b/_extensions/cours/_extensions/quarto-ext/latex-environment/_extension.yml @@ -0,0 +1,9 @@ +title: LaTeX Environment +author: Posit Software, PBC +version: 1.2.1 +quarto-required: ">=1.3" +contributes: + filters: + - latex-environment.lua + format: + pdf: default diff --git a/_extensions/cours/_extensions/quarto-ext/latex-environment/latex-environment.lua b/_extensions/cours/_extensions/quarto-ext/latex-environment/latex-environment.lua new file mode 100644 index 0000000..389a25f --- /dev/null +++ b/_extensions/cours/_extensions/quarto-ext/latex-environment/latex-environment.lua @@ -0,0 +1,150 @@ +-- environment.lua +-- Copyright (C) 2020 by RStudio, PBC + +local classEnvironments = pandoc.MetaMap({}) +local classCommands = pandoc.MetaMap({}) + +-- helper that identifies arrays +local function tisarray(t) + local i = 0 + for _ in pairs(t) do + i = i + 1 + if t[i] == nil then return false end + end + return true +end + +-- reads the environments +local function readEnvironments(meta) + local env = meta['environments'] + if env ~= nil then + if tisarray(env) then + -- read an array of strings + for i, v in ipairs(env) do + local value = pandoc.utils.stringify(v) + classEnvironments[value] = value + end + else + -- read key value pairs + for k, v in pairs(env) do + local key = pandoc.utils.stringify(k) + local value = pandoc.utils.stringify(v) + classEnvironments[key] = value + end + end + end +end + +local function readCommands(meta) + local env = meta['commands'] + if env ~= nil then + if tisarray(env) then + -- read an array of strings + for i, v in ipairs(env) do + local value = pandoc.utils.stringify(v) + classCommands[value] = value + end + else + -- read key value pairs + for k, v in pairs(env) do + local key = pandoc.utils.stringify(k) + local value = pandoc.utils.stringify(v) + classCommands[key] = value + end + end + end +end + +local function readEnvsAndCommands(meta) + readEnvironments(meta) + readCommands(meta) +end + +-- use the environments from metadata to +-- emit a custom environment for latex +local function writeEnvironments(divEl) + if quarto.doc.is_format("latex") then + for k, v in pairs(classEnvironments) do + if divEl.attr.classes:includes(k) then + -- process this into a latex environment + local beginEnv = '\\begin' .. '{' .. v .. '}' + local endEnv = '\n\\end{' .. v .. '}' + + -- check if custom options or arguments are present + -- and add them to the environment accordingly + local opts = divEl.attr.attributes['options'] + if opts then + beginEnv = beginEnv .. '[' .. opts .. ']' + end + + local args = divEl.attr.attributes['arguments'] + if args then + beginEnv = beginEnv .. '{' .. args .. '}' + end + + -- if the first and last div blocks are paragraphs then we can + -- bring the environment begin/end closer to the content + if #divEl.content > 0 and divEl.content[1].t == "Para" and divEl.content[#divEl.content].t == "Para" then + table.insert(divEl.content[1].content, 1, pandoc.RawInline('tex', beginEnv .. "\n")) + table.insert(divEl.content[#divEl.content].content, pandoc.RawInline('tex', "\n" .. endEnv)) + else + table.insert(divEl.content, 1, pandoc.RawBlock('tex', beginEnv)) + table.insert(divEl.content, pandoc.RawBlock('tex', endEnv)) + end + return 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 +-- emit a custom environment for latex +local function writeCommands(spanEl) + if quarto.doc.is_format("latex") then + for k, v in pairs(classCommands) do + if spanEl.attr.classes:includes(k) then + + -- resolve the begin command + local beginCommand = '\\' .. pandoc.utils.stringify(v) + local opts = spanEl.attr.attributes['options'] + local args = spanEl.attr.attributes['arguments'] + if opts then + beginCommand = beginCommand .. buildCommandArgs(opts, "[%s]") + end + if args then + beginCommand = beginCommand .. buildCommandArgs(args, "{%s}") + end + + local beginCommandRaw = pandoc.RawInline('latex', beginCommand .. '{') + + -- the end command + local endCommandRaw = pandoc.RawInline('latex', '}') + + -- attach the raw inlines to the span contents + local result = spanEl.content + table.insert(result, 1, beginCommandRaw) + table.insert(result, endCommandRaw) + + return result + end + end + end +end + +-- Run in two passes so we process metadata +-- and then process the divs +return { + { Meta = readEnvsAndCommands }, + { Div = writeEnvironments, Span = writeCommands } +} diff --git a/_extensions/cours/after-header-includes.latex b/_extensions/cours/after-header-includes.latex new file mode 100644 index 0000000..122d71f --- /dev/null +++ b/_extensions/cours/after-header-includes.latex @@ -0,0 +1,53 @@ +%% HEADER AND FOOTER + +\newcommand*\circled[1]{ + \tikz[baseline=(char.base)]{ + \node[shape=circle,draw,inner sep=2pt] (char) {#1}; + } +} + +\ohead{} + +% define the page numbering style +\pagenumbering{arabic} +% clear the defauls page header and footer, so the standard page numbering +% \clearpairofpagestyles + +% set my own numbering form for the footer +\cfoot*{\thepage\ /\ \pageref{LastPage}} + +\pagestyle{scrheadings} +\setkomafont{pagehead}{\normalfont\bfseries} +\setkomafont{pagefoot}{\normalfont} + +\RedeclareSectionCommand[ + beforeskip=1.0\baselineskip, + afterskip=0.5\baselineskip, + font=\sffamily\bfseries\Large +]{section} +\renewcommand \thesection{\Roman{section}} +\renewcommand*{\sectionformat}{\thesection.\enskip} + +\RedeclareSectionCommand[ + beforeskip=1.0\baselineskip, + afterskip=0.5\baselineskip, + font=\sffamily\bfseries\large, + indent=2em +]{subsection} +\renewcommand \thesubsection{\arabic{subsection}} +\renewcommand*{\subsectionformat}{\thesubsection)\enskip} + +\RedeclareSectionCommand[ + beforeskip=1.0\baselineskip, + afterskip=0.5\baselineskip, + font=\sffamily\bfseries\large, + indent=4em +]{subsubsection} +\renewcommand \thesubsubsection{\alph{subsubsection}} +\renewcommand*{\subsubsectionformat}{\circled{\thesubsubsection}\enskip} + + + +%% GRAPHICS +\graphicspath{{images/}} + diff --git a/_extensions/cours/before-body.tex b/_extensions/cours/before-body.tex new file mode 100644 index 0000000..e69de29 diff --git a/_extensions/cours/before-title.tex b/_extensions/cours/before-title.tex index 2d3e831..e23e053 100644 --- a/_extensions/cours/before-title.tex +++ b/_extensions/cours/before-title.tex @@ -1,73 +1,11 @@ -%% CAPTION - -\usepackage{caption} -\captionsetup{font=small} -\captionsetup[figure]{labelfont=bf, textfont=it, name=Document} -\captionsetup[table]{labelfont=bf, textfont=it, name=Document} - - - -%% TASKS - -\usepackage{tasks} -\settasks{ - label-format = {\bfseries} -} - - - -%% SIUNITX - -\usepackage[]{siunitx} -\sisetup{ - locale=FR, - output-decimal-marker={,}, - inter-unit-product={\ensuremath{ { } \cdot { } }}, - math-micro=\text{µ}, - text-micro=µ, -} - - - -%% HEADER AND FOOTER - -\usepackage{pageslts} -\usepackage[footsepline, plainfootsepline]{scrlayer-scrpage} -\pagestyle{scrheadings} -\setkomafont{pagehead}{\normalfont\bfseries} -\setkomafont{pagefoot}{\normalfont} - -\ohead{} - -\pagenumbering{arabic} -% clear the defauls page header and footer, so the standard page numbering -% \clearpairofpagestyles - -% set my own numbering form for the footer -\cfoot*{\thepage\ /\ \pageref{LastPage}} - - - -%% SECTIONS TITLES - -\usepackage{titlesec} -\titleformat{\section}[block] - {\sffamily\bfseries\Large} - {\thesection.}{.5em}{}[] -\titleformat{\subsection}[block] - {\sffamily\bfseries\large\hspace{2em}} - {\thesubsection)}{.5em}{}[] -\titleformat{\subsubsection}[block] - {\sffamily\bfseries\large\hspace{2em}} - {\circled{\thesubsubsection}}{.5em}{}[] -\renewcommand \thesection{\Roman{section}} -\renewcommand \thesubsection{\arabic{subsection}} -\renewcommand \thesubsubsection{\alph{subsubsection}} - - - -%% GRAPHICS -\graphicspath{{images/}} - - +%% DYNAMIC TITLE +$if(type-document.cours)$ +\rohead*[Cours]{Cours - $subtitle$} +$elseif(type-document.exercice)$ +\rohead*[Exercices]{Exercices - $subtitle$} +$elseif(type-document.activite)$ +\rohead*[Activité]{Activité - $subtitle$} +$else$ +\rohead*{$subtitle$} +$endif$ \ No newline at end of file diff --git a/_extensions/cours/header-setup.tex b/_extensions/cours/header-setup.tex new file mode 100644 index 0000000..a3320a6 --- /dev/null +++ b/_extensions/cours/header-setup.tex @@ -0,0 +1,11 @@ +%% DYNAMIC TITLE + +$if(type.cours)$ +\lohead*{Cours - \@subtitle} +$elseif(type.exercice)$ +\lohead*{Exercices - $subtitle$} +$elseif(type.activite)$ +\lohead*{Activité - $subtitle$} +$else$ +\lohead*{$subtitle$} +$endif$ \ No newline at end of file diff --git a/_extensions/cours/header.tex b/_extensions/cours/header.tex index bea29cc..9ad2871 100644 --- a/_extensions/cours/header.tex +++ b/_extensions/cours/header.tex @@ -1,4 +1,5 @@ -% TODO: Add custom LaTeX header directives here +%% PACKAGES TO LOAD IN THE HEADER OF THE DOCUMENT + \usepackage{polyglossia} \setdefaultlanguage{french} \usepackage{luatextra} @@ -11,6 +12,9 @@ \usepackage{asymptote} \usepackage{mathrsfs} +\usepackage{tkz-base} +\usepackage{tkz-euclide} +\usetikzlibrary{arrows, calc, patterns, positioning, shapes.geometric, shadows, snakes, tikzmark} \usepackage{array} \usepackage{tabularray} @@ -44,6 +48,12 @@ \usepackage[]{hyperref} \usepackage{chngcntr} +\usepackage{pageslts} +\usepackage[footsepline, plainfootsepline]{scrlayer-scrpage} + +\usepackage{tabularray} + \usepackage{lipsum} + diff --git a/_extensions/cours/title.tex b/_extensions/cours/title.tex index 88faa62..2f365bd 100644 --- a/_extensions/cours/title.tex +++ b/_extensions/cours/title.tex @@ -1,6 +1,5 @@ %% TITLE -%\usepackage{titling} $if(title)$ \title{$title$} $endif$ @@ -16,3 +15,4 @@ $endif$ $if(date)$ \date{$date$} $endif$ + diff --git a/template.pdf b/template.pdf index e0d5be4..57c0a46 100644 Binary files a/template.pdf and b/template.pdf differ diff --git a/template.qmd b/template.qmd index 9ce582a..67e5d4d 100644 --- a/template.qmd +++ b/template.qmd @@ -1,8 +1,9 @@ --- -title: "Cours avec Quarto" -subtitle: "Sous-titre" -format: - cours-pdf: default +title: "Template Quarto" +subtitle: "pour mes documents" +type-document: + cours: true +format: cours-pdf author: Jeff LANCE date: last-modified --- @@ -10,7 +11,7 @@ date: last-modified # Introduction Cette extension est un template pour mes documents de cours.\ -Elle est basée sur ma classe $\LaTeX$ ``latex-homework/jl-cours``. +Elle est basée sur ma classe $\LaTeX$ `latex-homework/jl-cours`. Ce document est un exemple d'usage de ce template. @@ -22,7 +23,23 @@ Ce document est un exemple d'usage de ce template. \lipsum[1] -## More Information +### Une sous-sous-section + +\lipsum[1] + +# Tableaux avec ``tabularray`` + +\begin{center} + \begin{tblr}{ + colspec={Q[red9,l]cccQ[green9,r]}, + hlines, vlines + } + cell 1-1 & cell 1-2 & cell 1-3 & cell 1-4 & cell 1-5 \\ + cell 2-1 & cell 2-2 & cell 2-3 & cell 2-4 & cell 2-5 + \end{tblr} +\end{center} + +# More Information You can learn more about controlling the appearance of PDF output here: