diff options
-rw-r--r-- | rst_context.lua | 84 | ||||
-rw-r--r-- | rst_setups.lua | 34 |
2 files changed, 106 insertions, 12 deletions
diff --git a/rst_context.lua b/rst_context.lua index 288df02..1ea681f 100644 --- a/rst_context.lua +++ b/rst_context.lua @@ -63,6 +63,11 @@ rst_context.lastitemnumber = 0 -- enumerations in RST allow arbitrary ski rst_context.current_footnote_number = 0 rst_context.current_symbolnote_number = 0 +function rst_context.addsetups(item) + state.addme[item] = state.addme[item] or true + return 0 +end + function rst_context.footnote_reference (label) local tf = state.footnotes if label:match("^%d+$") then -- all digits @@ -86,21 +91,11 @@ function rst_context.footnote_reference (label) rst_context.current_symbolnote_number = rc return [[\\symbolnote{\\getbuffer[__footnote_symbol_]].. rc .."]}" else -- “citation reference” for now treating them like footnotes - local rc = rst_context.current_footnote_number - rc = rc + 1 - --rst_context.current_footnote_number = rst_context.current_footnote_number + 1 - --print("creating footnote nr " .. rc) - rst_context.current_footnote_number = rc - return [[\\footnote{\\getbuffer[__footnote_number_]].. rc .."]}" - --return [[\\cite{]] .. label .. "}" + rst_context.addsetups("citations") + return [[\\cite{]] .. label .. [[}]] end end -function rst_context.addsetups(item) - state.addme[item] = state.addme[item] or true - return 0 -end - do local w = S" \v\t\n" / "_" local wp = Cs((w + 1)^1) @@ -134,6 +129,8 @@ function rst_context.literal (str) --return [[\\starttyping ]] .. str .. [[\\stoptyping]] end +--- ROLES for interpreted text + rst_context.roles = {} rst_context.roles.emphasis = rst_context.emphasis rst_context.roles.strong_emphasis = rst_context.strong_emphasis @@ -165,6 +162,69 @@ rst_context.roles.color = function(color, str) return string.format([[\\colored[%s]{%s}]], definition, str) end +--- Inofficial text roles for my private bib + +-- Afterthought: +-- Different citation commands are essentially typographical instructions: +-- they are concerned with the final representation of the data with respect to +-- a concrete implementation. Not the thing at all that would make reST +-- portable. But then its support for Python-style string escaping &c. ain’t at +-- all portable either. The problem is the same with XML written to be +-- processed with ConTeXt -- when processing the text directly in MkIV you’ll +-- always find yourself adding setups that allow fine-grained control of the +-- typeset output. At the same time those instructions directly contradict the +-- main reason for XML: to provide an application-independent data markup. +-- Typesetting XML (and now reST) with TeX, you will always end up writing TeX +-- code disguised in XML brackets. (Btw. the docutils reST specification has +-- the same kind of inclination to HTML -- some of its components don’t even +-- have a meaning save in HTML peculiarities.) If you strive to avoid this +-- *and* would like to have decent typesetting, you should use the +-- automatically generated TeX code as a starting point for the actual +-- typesetting job. Wish it was possible to have both -- the data in a +-- universal form and the output in the Optimal Typesetting System -- but +-- that’s a dream for now. If you really read these musings, then prove me +-- wrong if you can! Or go tell those digital publishers and their willing +-- subordinates, the authors, who think they can save a few pennys, +-- substituting the typesetter and editor by some fancy software. Keep in mind +-- that zapf.tex is not just random dummy text. Now, where was I? + +function rst_context.roles.ctsh(str) -- shorthand + rst_context.addsetups("citator") + return [[\\ctsh{]] .. str .. [[}]] +end + +function rst_context.roles.ctas(str) -- short cite + rst_context.addsetups("citator") + return [[\\ctas{]] .. str .. [[}]] +end + +function rst_context.roles.ctau(str) -- author only + rst_context.addsetups("citator") + return [[\\ctau{]] .. str .. [[}]] +end + +function rst_context.roles.cttt(str) -- title only + rst_context.addsetups("citator") + return [[\\cttt{]] .. str .. [[}]] +end + +function rst_context.roles.ctay(str) -- author year + rst_context.addsetups("citator") + return [[\\ctay{]] .. str .. [[}]] +end + +function rst_context.roles.ctfu(str) -- full cite + rst_context.addsetups("citator") + return [[\\ctfu{]] .. str .. [[}]] +end + +function rst_context.roles.nocite(str) -- nocite + rst_context.addsetups("citator") + return [[\\nocite[]] .. str .. [=[]]=] +end + +--- End citator roles + function rst_context.interpreted_text (...) local tab = { ... } local role, str diff --git a/rst_setups.lua b/rst_setups.lua index 1b2428a..917eebb 100644 --- a/rst_setups.lua +++ b/rst_setups.lua @@ -323,5 +323,39 @@ function optional_setups.danger () end +function optional_setups.citations () + local cit = [[ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Citations % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\setupbibtex[database=\jobname] +]] + + + return cit +end + +function optional_setups.citator () + local cit = [[ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Citator Options % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\usemodule[citator] +\loadbibdb{\jobname.bib} +\setupcitator[sortmode=authoryear] +\setupcite[mainmode=authoryear] + +\startbuffer[bibliography] +\chapter{References} +\setupbodyfont[small] +\bibbykey{shorthand}{all}{author} +\stopbuffer + +\prependtoks \getbuffer[bibliography] \to \everystoptext +]] + + return cit +end + return optional_setups |