Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using \setnotetext[footnote][0001]{This is a footnote.} to set a footnote's text and \note[footnote][0001] to create multiple references to it. When the footnote's first appearance, and later appearances appear within about 10 pages, this works okay, however, if the distance is too far, it becomes unwieldy to refer to footnotes appearing so far back, given the complexity of the document. How can I get ConTeXt to assign a new number to the footnote, and display the same text at the bottom of the page, it it has not done so for 10 or more pages and it happens to be referenced again? E.g.:

 _______________________
|                       |
| This is some text.^1  |
|                       |
|                       | (page 1)
| ....                  |
| 1 This is a footnote. |
|_______________________|
 _______________________
|                       |
| This is some text.^1  |
|                       |
|                       | (page 6)
|                       |
|                       |
|_______________________|
 _______________________
|                       |
| This is some text.^2  |
|                       |
|                       | (page 14)
| ....                  |
| 2 This is a footnote. |
|_______________________|
 _______________________
|                       |
| This is some text.^2  |
|                       |
|                       | (page 16)
|                       |
|                       |
|_______________________|
 _______________________
|                       |
| This is some text.^3  |
|                       |
|                       | (page 70)
| ....                  |
| 3 This is a footnote. |
|_______________________|

How can I automatically assign the footnote a new number, and redisplay the text, if the last appearance of the footnote's text appeared more than 10 pages prior?

share|improve this question
1  
Is it not stylistic better to write the same footnote again? Because there are quite many pages in between. Or you could refer to this earlier section if that would be possible. Mostly, it is an important point if you have some remarks that reappear many times. You should probably think about this. –  strpeter Feb 15 '13 at 9:04
add comment

1 Answer

Context does not provide a builtin mechanism for this, but with a little effort one can create a wrapper around the note/*notation* functionality that dynamically generates new inserts if a threshold is reached.

Save this code as t-noteref.mkvi:

\startmodule [noteref]

\startluacode

  local texgetcount = tex.getcount

  local thresholds  = { } -- (string, (string, int)    hash_t) hash_t
  local occurrences = { } -- (string, (string, int)    hash_t) hash_t
  local contents    = { } -- (string, (string, string) hash_t) hash_t

  local noteref = function (tag, ref)

    local ttag = thresholds[tag]
    if not ttag then
      context ("<noteref: unknown note tag %s>", tag)
      return
    end

    local threshold = ttag[ref]
    if not threshold then
      context ("<noteref: undeclared reference %s for tag %s>",
               ref, tag)
      return
    end

    local currentpage = texgetcount "realpageno"

    local last = occurrences[tag][ref]

    local ref_id  = ref .. ":" .. last
    local diff    = currentpage - last

    if diff >= threshold then
      --- create new notetext with same content
      ref_id  = ref .. ":" .. currentpage
      occurrences[tag][ref] = currentpage
      context.setnotetext ({tag}, {ref_id}, contents[tag][ref])
    end

    --- typeset the note marker
    context.note ({tag}, {ref_id})

  end

  local initialize_tag = function (tag)
    local ctag, ttag, otag = { }, { }, { }
    contents[tag]     = ctag
    thresholds[tag]   = ttag
    occurrences[tag]  = otag
    return ctag, ttag, otag
  end

  local set_noteref = function (tag, ref, threshold, content)

    tag = tag and tostring (tag) or "<none>"
    local ctag = contents[tag]
    local ttag = thresholds[tag]
    local otag = occurrences[tag]
    if not ctag then --- initialize new
      ctag, ttag, otag = initialize_tag (tag)
    end

    ref = ref and tostring (ref) or "<none>"

    threshold = threshold and tonumber (threshold) or 10
    ttag[ref] = threshold
    ctag[ref] = content
    otag[ref] = -1/0
  end

  commands.set_noteref   = set_noteref
  commands.noteref       = noteref
\stopluacode

\unprotect

\unexpanded \def \definenoteref {%
  \dotripleempty \note_reference_define%
}

\def \note_reference_define [#tag][#reference][#threshold]#content{%
  \ifthirdargument
    \note_reference_define_indeed{#tag}{#reference}{#threshold}{#content}%
  \else
    \note_reference_define_indeed{\v!footnote}{#tag}{#reference}{#content}%
  \fi%
}

\def \note_reference_define_indeed #tag#reference#threshold#content{%
  \ctxcommand {set_noteref ("#tag", "#reference", #threshold,
                            "\luaescapestring{#content}")}%
}

\unexpanded \def \noteref {%
  \dodoubleempty \note_reference_command%
}

\def \note_reference_command [#tag][#reference]{%
  \ifsecondargument
    \note_reference_indeed{#tag}{#reference}%
  \else
    \note_reference_indeed{\v!footnote}{#reference}%
  \fi%
}

\def \note_reference_indeed #tag#reference{%
  \ctxcommand {noteref ("#tag", "#reference")}%
}

\def \footnoteref       {\noteref[\v!footnote]}
\def \definefootnoteref {\definenoteref[\v!footnote]}

\protect

\stopmodule

The module declares two primary user macros:

  • \definenoteref[<note>][<reference>][<threshold>]{<text>} creates a new entry of type <note> (e. g. footnote) that can be referred to by <reference>. The <threshold> must be an integer that determines how many pages must elapse before the footnote content <text> will be retypeset.

  • \noteref[<note>][<reference>] refers to the note of type <note> which has been defined as <reference>.

  • Since footnote is by far the most common type of note, the module provides two convenience aliases: \footnoteref[<reference>] is synonymous with \noteref[footnote][<reference>]. Likewise, \definefootnoteref[<reference>][<value>]{<content>} is shorthand for \definenoteref[footnote][<reference>][<value>]{<content>}.

The usage is simple: firstly, define a note using \definenoteref instead of \setnotetext. Now you can access it through \noteref the same way as with \note before.

\setuppapersize [A7,landscape]
\setupinteraction [state=start]

\usemodule [noteref]

\definefootnoteref [mynote][3]{%% same as \definenoteref[footnote][mynote][3] {...}
   This {\bold footnote} is going to be referred to repeatedly, though
   the insert should reappear only whenever the threshold is reached.
}

\starttext

  first occurrence: \footnoteref[mynote]

  \dorecurse {19} {
    \page [yes] inserted page no \recurselevel \par
    > foo\footnote {some unremarkable footnote before} \par
    > bar\footnoteref [mynote] \par
    > baz\footnote {some unremarkable footnote after} \par
  }

\stoptext

Note that these <reference> arguments despite their name are no longer actual references that can be referred to with ordinary means like \in and \at. This is a consequence of the dynamic insertion which creates a new real reference upon every repetition for consecutive \noteref’s to refer to.

Demo

Some additional remarks to your code: \footnotetext is shorthand for \setnotetext[footnote] (Cf. the source), so you can use \footnotetext[0001]{this is a footnote}. The same goes for \note which assumes its first argument is [footnote] if unspecified (Cf. the source). Thus, instead of \note[footnote][0001] it suffices to write \note[0001]

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.