ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Conditional float references
@ 2013-09-22 21:02 Marco Patzer
  2013-09-23 16:46 ` Hans Hagen
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Marco Patzer @ 2013-09-22 21:02 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1.1: Type: text/plain, Size: 1577 bytes --]

Hi,

a couple of times the question came up¹²³ how to create more
intelligent referencing. There are already mechanisms in the core,
namely \somewhere and \atpage but they both have drawbacks.
\somewhere happily prints its text if the figure is placed on the
same double page. In fact, no text at all should be printed if the
figure is visible. Furthermore it's a little verbose to use unless
hidden in a custom macro. \atpage on the other hand doesn't hesitate
to print “see figure 1.2 at page 42” while you're on page 42.

I'm aware that automatic generation of reference text is problematic
since the text depends on the placement of floats which in turn
depends on the text which might result in oscillation. I'm not sure
how likely this is to occur in practice.

I don't know if there's interest in integrating such functionality
into the core. I attached some code, a new macro \smartref, which
takes the same arguments as \in.

  \smartref{figure}[fig:somefigure]

- it prints the reference if it is on the same page
  (e.g. Figure 1.2)

- it prints the reference and a customizable text if the reference
  is on the next/previous page (e.g. Figure 1.2 on the previous page)

- it prints the reference and the page if the reference is further
  away than one page (e.g. Figure 1.2 on page 42)

- it adapts to single-sided and double-sided layouts


Marco

¹ http://thread.gmane.org/gmane.comp.tex.context/65295
² http://thread.gmane.org/gmane.comp.tex.context/59455
³ http://thread.gmane.org/gmane.comp.tex.context/76001

[-- Attachment #1.1.2: conditionalfloatreferences.mkvi --]
[-- Type: text/plain, Size: 3510 bytes --]

\unprotect\r\r\unexpanded\def\strc_references_smart\r  {\strc_references_start_goto\r   \let\currentreferencecontent\currentreferencedefault\r   \strc_references_pickup_smart_goto}\r\r\def\strc_references_pickup_smart_goto\r  {\dodoublegroupempty\strc_references_pickup_goto_smart_indeed}\r\r\starttexdefinition strc_references_pickup_goto_smart_indeed #left#right#dummy[#label]\r  \leftreferencetoks\r  \iffirstargument\r    {#left}\r  \else\r    \defaultleftreferencetoks\r    \let\leftofreferencecontent\empty\r  \fi\r  \rightreferencetoks\r  \ifsecondargument\r    {#right}\r  \else\r    \defaultrightreferencetoks\r    \let\rightofreferencecontent\empty\r  \fi\r  \doifreferencefoundelse{#label}\r    {\goto{\referencesequence}[#label]\r     \strc_references_check_visibility\r     \ifreferenceisvisible\else\r       \space\strc_references_smart_string\r     \fi}\r     {\let\currentreferencecontent\dummyreference\r      \goto{\referencesequence}[#label]}\r  \strc_references_stop_goto\r\stoptexdefinition\r\r\newif\ifreferenceisvisible \referenceisvisiblefalse\r\r\starttexdefinition strc_references_check_visibility\r  \def\strc_references_smart_string{\labeltext\v!atpage\currentreferencepage}\r  \referenceisvisiblefalse\r\r  \ifnum\referencepagestate=\plusone %% 1 = reference on current page\r    \referenceisvisibletrue\r  \else\r    \ifsinglesided\r      \strc_references_do_relative_else\plusone\r        {\def\strc_references_smart_string{\labeltext\v!nextpage}}\r        {\strc_references_do_relative\minusone\r         {\def\strc_references_smart_string{\labeltext\v!previouspage}}{}}\r    \else\r      \ifodd\realpageno\r        \strc_references_do_relative_else\minusone\r          {\def\strc_references_smart_string{\labeltext\v!previouspage}\r           \referenceisvisibletrue}\r          {\strc_references_do_relative_else\plusone\r           {\def\strc_references_smart_string{\labeltext\v!nextpage}}{}}\r      \else\r        \strc_references_do_relative_else\minusone\r          {\def\strc_references_smart_string{\labeltext\v!previouspage}}\r          {\strc_references_do_relative_else\plusone\r           \referenceisvisibletrue{}}\r      \fi\r    \fi\r  \fi\r\stoptexdefinition\r\r\starttexdefinition strc_references_do_relative_else #relativepagenumber\r  \ifnum\currentreferencerealpage=\numexpr\realpageno+#relativepagenumber\relax\r    \expandafter\firstoftwoarguments\r  \else\r    \expandafter\secondoftwoarguments\r  \fi\r\stoptexdefinition\r\r\let\smartref\strc_references_smart\r\r\startinterface all\r  \setinterfacevariable {previouspage} {previouspage}\r  \setinterfacevariable {nextpage}     {nextpage}\r\stopinterface\r\r\setuplabeltext\r  [\s!en]\r  [\v!atpage=on page\nobreakspace, %% “at page” sounds weird\r   \v!previouspage=on the previous page,\r   \v!nextpage=on the next page]\r\r\protect\r\r\useMPlibrary [dum]\r\setuppagenumbering [alternative=doublesided]\r\r\starttext\r\r      See \smartref{figure}[fig:alpha] and \smartref{figure}[fig:gamma].\r\page See \smartref{figure}[fig:alpha] and \smartref{figure}[fig:gamma].\r\r\startplacefigure [reference=fig:alpha] \externalfigure \stopplacefigure\r\startplacefigure [reference=fig:beta]  \externalfigure \stopplacefigure\r\r\page See \smartref{figure}[fig:alpha] and \smartref{figure}[fig:gamma].\r\r\startplacefigure [reference=fig:gamma] \externalfigure \stopplacefigure\r\startplacefigure [reference=fig:delta] \externalfigure \stopplacefigure\r\r\page See \smartref{figure}[fig:alpha] and \smartref{figure}[fig:gamma].\r\page See \smartref{figure}[fig:alpha] and \smartref{figure}[fig:gamma].\r\r\stoptext\r

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 11+ messages in thread
[parent not found: <mailman.222.1379923068.18665.ntg-context@ntg.nl>]
[parent not found: <mailman.236.1380044639.18665.ntg-context@ntg.nl>]

end of thread, other threads:[~2013-10-08 21:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-22 21:02 Conditional float references Marco Patzer
2013-09-23 16:46 ` Hans Hagen
2013-09-23 22:24   ` Marco Patzer
2013-09-25  3:46 ` Otared Kavian
2013-09-25  7:29   ` Marco Patzer
2013-09-25 14:40     ` Otared Kavian
2013-09-25 15:28       ` Marco Patzer
2013-10-08 21:23 ` Marco Patzer
     [not found] <mailman.222.1379923068.18665.ntg-context@ntg.nl>
2013-09-24 11:37 ` Robert Blackstone
2013-09-24 11:48   ` Marco Patzer
     [not found] <mailman.236.1380044639.18665.ntg-context@ntg.nl>
2013-09-24 19:52 ` Robert Blackstone

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).