Difference between revisions of "User:Wolfgang Schuster"

From ConTeXt wiki
Jump to navigationJump to search
(New imposition style XSIDE)
(brochure: missing \unprotect)
Line 113: Line 113:
  
 
\dorecurse{20}
 
\dorecurse{20}
{\startstandardmakeup[align=middle]
+
  {\startstandardmakeup[align=middle]
  Front side \recurselevel
+
  Front side \recurselevel
  \stopstandardmakeup
+
  \stopstandardmakeup
  \startstandardmakeup[align=middle]
+
  \startstandardmakeup[align=middle]
  Back side \recurselevel
+
  Back side \recurselevel
  \stopstandardmakeup}
+
  \stopstandardmakeup}
  
 
\stoptext
 
\stoptext
Line 126: Line 126:
  
 
<texcode>
 
<texcode>
 +
\unprotect
 +
 
\installpagearrangement LEAFLET
 
\installpagearrangement LEAFLET
 
   {\dosetuparrangement\@@ppnx1{\numexpr\@@ppnx*2\relax}{\numexpr\@@ppnx+\plusone\relax}2%
 
   {\dosetuparrangement\@@ppnx1{\numexpr\@@ppnx*2\relax}{\numexpr\@@ppnx+\plusone\relax}2%
Line 131: Line 133:
  
 
\def\pusharrangedpageLEAFLET#1%
 
\def\pusharrangedpageLEAFLET#1%
{\doglobal\increment\arrangedpageN
+
  {\doglobal\increment\arrangedpageN
  \reportarrangedpage\arrangedpageN
+
  \reportarrangedpage\arrangedpageN
  \ifnum\arrangedpageN=\plusone
+
  \ifnum\arrangedpageN=\plusone
    \handlearrangedpageXandY{#1}0{\numexpr\@@ppnx-1\relax}0\arrangedpageA
+
    \handlearrangedpageXandY{#1}0{\numexpr\@@ppnx-1\relax}0\arrangedpageA
  \else\ifnum\arrangedpageN>\numexpr\@@ppnx+1\relax
+
  \else\ifnum\arrangedpageN>\numexpr\@@ppnx+1\relax
    \handlearrangedpageXandY{#1}0{\numexpr\arrangedpageN-\@@ppnx-2\relax}0\arrangedpageA
+
    \handlearrangedpageXandY{#1}0{\numexpr\arrangedpageN-\@@ppnx-2\relax}0\arrangedpageA
  \else
+
  \else
    \handlearrangedpageXandY{#1}0{\numexpr\arrangedpageN-2\relax}0\arrangedpageB
+
    \handlearrangedpageXandY{#1}0{\numexpr\arrangedpageN-2\relax}0\arrangedpageB
  \fi\fi
+
  \fi\fi
  \ifnum\arrangedpageN=\arrangedpageT
+
  \ifnum\arrangedpageN=\arrangedpageT
    \poparrangedpages
+
    \poparrangedpages
  \fi}
+
  \fi}
  
 
\protect
 
\protect
Line 162: Line 164:
 
   \stopstandardmakeup}
 
   \stopstandardmakeup}
  
\stoptext
 
</texcode>
 
 
=== Arranging pages ===
 
 
<texcode>
 
\unprotect
 
 
\installpagearrangement XSIDE
 
  {\dosetuparrangement{\@@ppnx}{1}{\@@ppnx}{\numexpr\@@ppnx+\plusone\relax}2%
 
  \pusharrangedpageXSIDE\poparrangedpagesTWO\relax}
 
 
\def\pusharrangedpageXSIDE#1%
 
  {\doglobal\increment\arrangedpageN
 
  \reportarrangedpage\arrangedpageN
 
  \handlearrangedpageXandY{#1}0{\numexpr\arrangedpageN-1\relax}0\arrangedpageA
 
  \ifnum\arrangedpageN=\arrangedpageT
 
    \poparrangedpages
 
  \fi}
 
 
\protect
 
</texcode>
 
 
<texcode>
 
\setuppapersize[DL][A3,landscape]
 
\setuppaper    [nx=4]
 
\setuparranging[XSIDE]
 
\setuplayout  [location=middle,marking=on]
 
 
\starttext
 
\dorecurse{40}
 
{\startstandardmakeup[align=middle]
 
  \ssd Page \recurselevel
 
  \stopstandardmakeup}
 
 
\stoptext
 
\stoptext
 
</texcode>
 
</texcode>

Revision as of 21:20, 10 June 2009

Sample Code

Full page figures

The following macro allows me to include figures in my document and adjust them to have the size of a normal page.

\unprotect

\definesystemvariable{xx}

\def\fullpagebox
  {\dosingleempty\dofullpagebox}

\def\dofullpagebox[#1]%
  {\bgroup
   \getparameters[\??xx][\c!nx=1,\c!ny=1,#1]%
   \dowithnextbox
     {\!!widtha\dimexpr\paperwidth/\nextboxwd\relax
      \!!widthb\dimexpr\paperheight/\nextboxht\relax
      \ifdim\!!widtha>\!!widthb
        \setbox\nextbox\vbox\!!to\@@xxny\paperheight
          {\vss\expanded{\scale[\c!width=\@@xxnx\paperwidth]{\flushnextbox}}\vss}%
      \else
        \setbox\nextbox\hbox\!!to\@@xxnx\paperwidth
          {\hss\expanded{\scale[\c!height=\@@xxny\paperheight]{\flushnextbox}}\hss}%
      \fi
      \setbox\nextbox\hbox{\clip[\c!width=\@@xxnx\paperwidth,\c!height=\@@xxny\paperheight]{\flushnextbox}}%
      \startTEXpage
      \flushnextbox
      \stopTEXpage
      \egroup}%
   \hbox}

\def\fullpagefigure
  {\dodoubleempty\dofullpagefigure}

\def\dofullpagefigure[#1][#2]%
  {\ifsecondargument
     \fullpagebox[#1]{\externalfigure[#2]}%
   \else
     \fullpagebox[]{\externalfigure[#1]}%
   \fi}

\protect

\starttext

\fullpagefigure[image]

\fullpagefigure[nx=2][image]

\fullpagefigure[ny=2][image]

\stoptext

Flashcards

For tests and vocabulary it is usefull to use flashcards for learning.

\unprotect

\installpagearrangement FLASHCARD
  {\dosetuparrangement\@@ppnx\@@ppny{\numexpr\@@ppxy*2\relax}%
   {\numexpr\@@ppnx+\plusone\relax}{\numexpr\@@ppny+\plusone\relax}%
   \pusharrangedpageFLASHCARD\poparrangedpagesAB\relax}

\newcounter\arrangedpageshiftX
\newcounter\arrangedpageshiftY

\def\dopusharrangedpageFLASHCARD#1%
 {\ifnum\arrangedpageshiftX<\arrangedpageX
    \ifodd\arrangedpageN
      \handlearrangedpageXandY{#1}0\arrangedpageshiftX\arrangedpageshiftY\arrangedpageA
    \else
      \handlearrangedpageXandY{#1}0{\numexpr\@@ppnx-\arrangedpageshiftX-1\relax}\arrangedpageshiftY\arrangedpageB
      \doglobal\increment\arrangedpageshiftX
    \fi
  \fi
  \ifnum\arrangedpageshiftX=\@@ppnx
    \doglobal\newcounter\arrangedpageshiftX
    \doglobal\increment\arrangedpageshiftY
  \fi}

\def\pusharrangedpageFLASHCARD#1%
 {\doglobal\increment\arrangedpageN
  \reportarrangedpage\arrangedpageN
  \ifnum\arrangedpageN=\numexpr\@@ppxy*2\relax
    \dopusharrangedpageFLASHCARD{#1}%
    \doglobal\newcounter\arrangedpageshiftX
    \doglobal\newcounter\arrangedpageshiftY
    \poparrangedpages
  \else
    \dopusharrangedpageFLASHCARD{#1}%
  \fi}

\protect

To create cards you have to select a number of rows and columns and set the papersize to a value small enough to fit all cards on one sheet of paper.

\setuppapersize[A7][A3,landscape]
\setuppaper    [nx=4,ny=2]
\setuparranging[FLASHCARD]
\setuplayout   [location=middle,marking=on]

\setupbackgrounds[page][frame=on]

\starttext

\dorecurse{20}
  {\startstandardmakeup[align=middle]
   Front side \recurselevel
   \stopstandardmakeup
   \startstandardmakeup[align=middle]
   Back side \recurselevel
   \stopstandardmakeup}

\stoptext

Brochures

\unprotect

\installpagearrangement LEAFLET
  {\dosetuparrangement\@@ppnx1{\numexpr\@@ppnx*2\relax}{\numexpr\@@ppnx+\plusone\relax}2%
   \pusharrangedpageLEAFLET\poparrangedpagesAB\relax}

\def\pusharrangedpageLEAFLET#1%
  {\doglobal\increment\arrangedpageN
   \reportarrangedpage\arrangedpageN
   \ifnum\arrangedpageN=\plusone
     \handlearrangedpageXandY{#1}0{\numexpr\@@ppnx-1\relax}0\arrangedpageA
   \else\ifnum\arrangedpageN>\numexpr\@@ppnx+1\relax
     \handlearrangedpageXandY{#1}0{\numexpr\arrangedpageN-\@@ppnx-2\relax}0\arrangedpageA
   \else
     \handlearrangedpageXandY{#1}0{\numexpr\arrangedpageN-2\relax}0\arrangedpageB
   \fi\fi
   \ifnum\arrangedpageN=\arrangedpageT
     \poparrangedpages
   \fi}

\protect
\setuppapersize[DL][A3,landscape]
\setuppaper    [nx=3]
\setuparranging[LEAFLET]
\setuplayout   [location=middle,marking=on]

\setupbackgrounds[page][frame=on]

\starttext

\dorecurse{6}
 {\startstandardmakeup[align=middle]
  \ssd Page \recurselevel
  \stopstandardmakeup}

\stoptext

Dictionary entries in XML-format

Just a example how to use XML to store and access information.

In my example the content for the dictionary is stored in a buffer, to use a external file for the data the commented lines for MkII and MkIV are required.

% engine=pdftex

\startbuffer[lexicon]
<lexicon>
  <entry name='LaTeX'>
    <name>latex;</name>
    <description>Macro package from Leslie Lamport.</description>
  </entry>
  <entry name='ConTeXt'>
    <name>context;</name>
    <description>Macro package from Hans Hagen.</description>
  </entry>
  <entry name='TeX'>
    <name>tex;</name>
    <description>the program from von Donald E. Knuth.</description>
  </entry>
  <entry name='Pragma Ade'>
    <name>PRAGMA Advanced Document Engineering</name>
    <description>Hans Hagens company.</description>
  </entry>
</lexicon>
\stopbuffer

This is the MkII code to process the data above.

\definesorting[lexiconentry][lexicon]

\setupsorting
  [lexiconentry]
  [criterium=all,
   command=\placelexiconentry]

\definedescription
  [lexicon]
  [width=broad,
   hang=1]

\def\placelexiconentry#1%
  {\bgroup
   \enableXML
   \expanded{\flushXMLelement{name:#1}}%
   \egroup}

\defineXMLentities [tex]     {tex}     {\TeX}
\defineXMLentities [latex]   {latex}   {\LaTeX}
\defineXMLentities [context] {context} {\ConTeXt}

\defineXMLenvironment [entry]
  {\defineXMLsave[name]
   \defineXMLsave[description]}
  {\startlexicon{\XMLflush{name}}
   \XMLflush{description}
   \stoplexicon}

\startXMLmapping[lexicon:load]

\defineXMLenvironmentsave [entry] [name=]
  {}
  {\edef\currentLEXICONENTRY{\XMLop{name}}%
   \gsaveXMLdatainelement{name:\currentLEXICONENTRY}{entry}{entry}%
   \expanded{\lexiconentry[lexicon:\XMLop{name}]{\XMLop{name}}}%
   \setbox\scratchbox\hbox{\getvalue{lexicon:\XMLop{name}}}}

\stopXMLmapping

\def\loaddata
  {\dosingleargument\doloaddata}

\def\doloaddata[#1]%
  {\bgroup
   \endlinechar\minusone
   \startXMLmapping[lexicon:load]%
   %\expanded{\processXMLfilegrouped{#1}}%
   \expanded{\processXMLbuffer[#1]}%
   \stopXMLmapping
   \egroup}

\starttext
\loaddata[lexicon]
\placelistoflexicon
\stoptext

In MkIV we have direct access to the data can process the content without the previous step to save everything in macros.

\definesorting[lexiconentry][lexicon]

\setupsorting
  [lexiconentry]
  [criterium=all,
   command=\placelexiconentry]

\startxmlsetups xml:lexicon
  \xmlsetsetup{\xmldocument}{entry}{*}
\stopxmlsetups

\xmlregistersetup{xml:lexicon}

\startxmlsetups entry
  \expanded{\lexiconentry[lexicon:\xmlatt{#1}{name}]{\xmlatt{#1}{name}}}
  \setbox\scratchbox\hbox{\getvalue{lexicon:\xmlatt{#1}{name}}}
\stopxmlsetups

\definedescription
  [lexicon]
  [width=broad,
   hang=1]

\def\placelexiconentry#1%
  {\bgroup
   \enableXML
   \xmlfilter{lexicon:process}{/lexicon/entry[@name='#1']}
   \egroup}

\defineXMLentities [tex]     {tex}     {\TeX}
\defineXMLentities [latex]   {latex}   {\LaTeX}
\defineXMLentities [context] {context} {\ConTeXt}

\defineXMLenvironment [entry]
  {\defineXMLsave[name]
   \defineXMLsave[description]}
  {\startlexicon{\XMLflush{name}}
   \XMLflush{description}
   \stoplexicon}

\xmlprocessbuffer{lexicon:load}{lexicon}{}

\starttext
\xmlloadbuffer{lexicon:process}{lexicon}
\placelistoflexicon
\stoptext


Feature Requests

  • grid=yes option for \definelayout,
  • temporary user variable for privat macros (see above),
  • macro \defineuvervariable{...} to define namespaces for third party modules.
  • New version of the \startfigure environment


Links