summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-13 17:34:30 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-13 17:34:30 +0200
commitaaa9cbae61d38d9011270d1a6a19226fd5258be2 (patch)
tree374819fed79ed43875db8f5c2721d6bdd3022629 /rst_context.lua
parent0e03fb445570cd787a61edc2050a46d96b4be491 (diff)
downloadcontext-rst-aaa9cbae61d38d9011270d1a6a19226fd5258be2.tar.gz
symbol footnotes. separate setups.
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua89
1 files changed, 76 insertions, 13 deletions
diff --git a/rst_context.lua b/rst_context.lua
index bc96a9a..5c36c54 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -48,23 +48,40 @@ rst_context.last_section_level = 0
rst_context.anonymous_links = 0
rst_context.context_references = {}
-rst_context.current_footnote_number = 0
+rst_context.current_footnote_number = 0
+rst_context.current_symbolnote_number = 0
function rst_context.footnote_reference (label)
- local tf = tracklists.footnotes
+ local tf = state.footnotes
if label:match("^%d+$") then -- all digits
- -- TODO
+ local c = tonumber(label)
+ print("creating footnote nr " .. c)
+ return [[\\footnote{\\getbuffer[__footnote_number_]].. c .."]}"
elseif label == "#" then --autonumber
- rst_context.current_footnote_number = rst_context.current_footnote_number + 1
- print("creating footnote nr " .. rst_context.current_footnote_number)
- return [[\\footnote{\\getbuffer[__autonumber]]..rst_context.current_footnote_number.."]}"
+ 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 .."]}"
elseif label:match("^#.+$") then
- -- TODO
+ local thelabel = label:match("^#(.+)$")
+ print("creating labeled footnote " .. thelabel)
+ return [[\\footnote{\\getbuffer[__footnote_label_]].. thelabel .."]}"
elseif label == "*" then
- -- TODO
+ local rc = rst_context.current_symbolnote_number
+ rc = rc + 1
+ print("creating symbolnote nr " .. rc)
+ rst_context.current_symbolnote_number = rc
+ return [[\\symbolnote{\\getbuffer[__footnote_symbol_]].. rc .."]}"
end
end
+function rst_context.addsetups(item)
+ state.addme[item] = state.addme[item] or true
+ return 0
+end
+
-- So we can use crefs[n][2] to refer to the place where the reference was
-- created.
local function get_context_reference (str)
@@ -304,8 +321,8 @@ local inline_parser = P{
,
footnote_label = V"digit"^1
- + V"gartenzaun"
+ V"gartenzaun" * V"letter"^1
+ + V"gartenzaun"
+ V"asterisk"
,
@@ -321,9 +338,15 @@ local inline_parser = P{
url_path = V"slash" * (V"url_path_char"^1 * V"slash"^-1)^1,
}
-function rst_context.paragraph (tab)
- local str = inline_parser:match(table.concat(tab, " "))
- --print(inline_parser:match(table.concat(tab, " ")))
+function rst_context.paragraph (data)
+ local str
+ if not data then
+ return ""
+ elseif type(data) == "table" then
+ str = inline_parser:match(table.concat(data, " "))
+ else
+ str = data
+ end
return string.format([[
\\startparagraph
@@ -840,7 +863,8 @@ function rst_context.simple_table(tab)
end
function rst_context.footnote(label, content)
- local tf = tracklists.footnotes
+ local tf = state.footnotes
+ rst_context.addsetups("footnotes")
if label:match("^%d+$") then -- all digits
tf.numbered[tonumber(label)] = content
elseif label == "#" then --autonumber
@@ -852,10 +876,49 @@ function rst_context.footnote(label, content)
local thelabel = label:match("^#(.+)$")
tf.autolabel[thelabel] = content
elseif label == "*" then
+ rst_context.addsetups("footnote_symbol")
tf.symbol[#tf.symbol+1] = content
end
return ""
end
+optional_setups = {}
+function optional_setups.footnote_symbol ()
+ local setup = [[
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Footnotes with symbol conversion %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\definenote[symbolnote][footnote]
+\setupnote [symbolnote][way=bypage,numberconversion=set 2]
+]]
+ return setup
+end
+
+function optional_setups.footnotes ()
+ local tf = state.footnotes
+ local fn = [[
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Footnotes %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+]]
+ local buffer = [[
+
+%% %s
+\startbuffer[%s]
+%s\stopbuffer
+]]
+
+ for nf, note in next, tf.numbered do
+ fn = fn .. string.format(buffer, "Autonumbered footnote", "__footnote_number_"..nf, note)
+ end
+ for nf, note in next, tf.autolabel do
+ fn = fn .. string.format(buffer, "Labeled footnote", "__footnote_label_"..nf, note)
+ end
+ for nf, note in next, tf.symbol do
+ fn = fn .. string.format(buffer, "Symbol footnote", "__footnote_symbol_"..nf, note)
+ end
+ return fn
+end
return rst_context