4

Consider the following Pandoc-generated ConTeXt document:

\setuppapersize [A4][A4]
\setuplayout    [width=middle,  backspace=1.5in, cutspace=1.5in,
                 height=middle, topspace=0.75in, bottomspace=0.75in]

\setuppagenumbering[location={footer,center}]

\setupexternalfigures[
  order={svg,pdf,png,jpg},
  location=global,
  wfactor=fit,
  ]

\definedescription
  [description]
  [headstyle=bold, style=normal, location=hanging, width=4cm]

\starttext
\placefigure[here,nonumber]{Little kitten}{\externalfigure[http://placekitten.com/g/480/300][method=jpg]}

\startdescription{{\externalfigure[http://placekitten.com/g/640/400][method=jpg]}}
  \input bryson
\stopdescription
\stoptext

current output

Question

Little kitten should grow to \textwidth. The other kitten should fit through a width of 4cm with text wrapped around it. Its picture should be flush at the top with the wrapped text.

The kittens may not be touched; only the setup before \starttext may be changed. Furthermore, no references to the image URLs should appear in the preamble for this problem to be solved as generally as possible.

I tried something with \setupexternalfigures and wfactor=fit but it does not seem to work.

  • 1
    With your input and a recent context I get exactly the result you describe and not what your screenshots show. Maybe updating your context version already solves the problem. – Marco Sep 04 '13 at 13:58
  • @Marco context --version yields ConTeXt Process Management 0.52 and current version: 2012.05.30 11:26. I will test on a SolydX machine later on and report back here. This rolling Debian Testing release should have a more recent version of ConTeXt in its repositories. – Serge Stroobandt Sep 04 '13 at 16:12
  • 1
    Instead of using the distros repository I'd suggest to install ConTeXt standalone. It can be installed as a regular user, no admin rights required, and it's the most up-to-date version. – Marco Sep 04 '13 at 16:30
  • @Marco Are you using the beta or current stable version? – Serge Stroobandt Sep 04 '13 at 17:18
  • 1
    @SergeStroobandt: In terms of ConTeXt development speed, 2012.05.30 is a stoneage distribution. I normally install ConTeXt beta. – Aditya Sep 04 '13 at 17:40
  • 1
    BTW, setting the image as the description title is a sneaky way of wrapping text around an image. Are you generating only tex/pdf output or do you also care about other formats? In the former case, have a look at the filter module; in the latter case, consider using a preprocessor to be able to extend markdown. – Aditya Sep 04 '13 at 17:43
  • @Aditya It is the latter case; I also care about HTML output. The "sneaky" trick is a classic CSS trick of Dan Cederholm's Bullet Proof Web Design. I had read your preprocessor post before with much interest. However, I first would like to try and see if I can do without. ConTeXt promises separation of style from content, so I gather this should not pose any problem? – Serge Stroobandt Sep 04 '13 at 20:20
  • Currently, Debian Testing also offers only version: 2012.05.30 11:26. – Serge Stroobandt Sep 05 '13 at 07:27

2 Answers2

2

Solution

With version: 2012.05.30 11:26 of ConTeXt, \setupexternalfigures[wfactor=fit] has no effect. Hence, the following solution which also keeps in-line figures intact.

This is all really nice, because LaTeX2e has not be found capable (yet) of pulling off a similar feat. In contrast to ConTeXt, float clearing is not automatic in LaTeX2e; instead, one needs to fuddle around with distance measurements.

\setuppapersize [A4][A4]
\setuplayout    [width=middle,  backspace=1.5in, cutspace=1.5in,
                 height=middle, topspace=0.75in, bottomspace=0.75in]

\setuppagenumbering[location={footer,center}]

\setuptolerance[horizontal, tolerant, stretch]

% Keep old definitions \let\oldplacefigure\placefigure \let\oldexternalfigure\externalfigure

% For full text-width figures \def\placefigure[#1]#2#3{% \def\externalfigure[##1]{\oldexternalfigure[##1][method=jpg, wfactor=fit]}% \oldplacefigure[#1]{#2}{#3}% \let\externalfigure\oldexternalfigure% Reset for in-line figures }

% For figures with wrapped text \definedescription[description][ headstyle=bold, style=normal, location=hanging, width=4cm ]

\def\startdescription#1{% \def\externalfigure[##1]{\oldexternalfigure[##1][method=jpg, width=4cm]}% \oldplacefigure[none,left,high]{}{#1}% \let\externalfigure\oldexternalfigure% Reset for in-line figures } \def\stopdescription{\endgraf}

\starttext \placefigure[here,nonumber]{Little kitten}{\externalfigure[http://placekitten.com/g/480/300]}

\startdescription{{\externalfigure[http://placekitten.com/g/640/400]}} \input bryson \stopdescription \stoptext

output

Caveat

The cats have a caveat though; When the figure with the description occurs near the end of a page, its wrapped text will fall off the page like in the following example. I distilled a minimum working example out of it and linked it as a follow-up question.

caveat

Newer ConTeXt versions

Eventually, I found how to install ConTeXt Standalone under Debian. I can confirm that \setupexternalfigures[wfactor=fit] is now functional in ConTeXt version: 2013.09.09 19:45. This can significantly reduce the code when, like in the example above, no in-line images are used. However, when in a more general case in-line images are present, [wfactor=fit] cannot be used because it acts also upon these. [wfactor=fit] acting upon in-line images could be considered a ConTeXt bug. Therefore, above solution which also works with older ConTeXt versions, remains the more general solution.

  • 1
    Keep in mind that in the newer version, you will need to use alternative=... instead of location=... for the description environment. – Aditya Sep 07 '13 at 15:05
1

Really, you are using the wrong (ConTeXt) markup to achieve the affect. However, I'll provide a solution that answers your question (without answering your question :)

The requirement stated:

only the setup before \starttext may be changed.

So, here it goes:

\setuppapersize [A4][A4]
\setuplayout    [width=middle,  backspace=1.5in, cutspace=1.5in,
                 height=middle, topspace=0.75in, bottomspace=0.75in]

\setuppagenumbering[location={footer,center}]

\setupexternalfigures
  [
    order={svg,pdf,png,jpg},
    location=global,
    wfactor=fit,
  ]

\definedescription
  [description]
  [headstyle=bold, style=normal, alternative=hanging, width=4cm]

\definefloat[hangingfigure]
            [hangingfigures]
            [figures]

\setupfloat [hangingfigure]
            [
              default={left,none},
            ]

\def\startdescription{\placehangingfigure\empty}
\def\stopdescription{\endgraf}

\useexternalfigure[http://placekitten.com/g/640/400]
                  [http://placekitten.com/g/640/400]
                  [method=jpg,width=4cm]

\starttext
    \placefigure[here,nonumber]{Little kitten}{\externalfigure[http://placekitten.com/g/480/300][method=jpg]}

  \startdescription{{\externalfigure[http://placekitten.com/g/640/400][method=jpg]}}
    \input bryson
  \stopdescription
\stoptext

which gives

enter image description here

More seriously, markdown provides too few markup options to achieve complicated elements. My own solution is to use a preprocessor to give it a boost, but YMMW.

Aditya
  • 62,301
  • In my 2012.05.30 version of ConTeXt, the above code produces an error on line 37, as you can see for yourself by pasting the code to live.contextgarden.net. Also, the "hard" URL links in \useexternalfigure do not make this a generally applicable solution that can be used with Pandoc-generated documents. I will add this requirement to the question. I would like to try this out with a newer ConTeXt version, but I am experiencing problems with the installation under Debian. This does not take away that I very much appreciate your answer. – Serge Stroobandt Sep 05 '13 at 12:54
  • I know that using \useexternalfigure makes this solution useless in the generic case, and that is why I said that it really doesn't answer your question. Newer version of pandoc allows you to write your own writer using lua (though I have not tried it). Using that you may be able to translate pandoc code into something that is easier to tweak at ConTeXt end. – Aditya Sep 05 '13 at 15:24
  • 1
    For the error with old version of ConTeXt, use the following definition instead: \def\startdescription#1{\placefigure[left,none]{}{#1}} – Aditya Sep 05 '13 at 15:28
  • Thanks, that resolved the error. However, little kitten is still small over here. I was also wondering whether a \def\externalfigure redefinition within the \def\startdescription definition were possible to eliminate the hard URL-linking. – Serge Stroobandt Sep 05 '13 at 16:47
  • Rather than redefining externalfigures, you could try \setupextranlfigure[width=4cm] inside the definition of \startdescription. – Aditya Sep 05 '13 at 17:48