1

I'm new to ConTeXt and am trying to make a small theme for my presentations to get to know it better.

My slides have a title and a subtitle positioned in the header. I want to have random lines between the title and subtitle. The lines should join and become horizontal when passing directly between the title and subtitle.

I removed the irrelevant parts of my document. There is currently one line and it becomes flat near the centre for a length w. I'm trying to get the value of w from outside the MPpage.

To clarify a bit, here is what I currently get with the fixed value (sorry, those are screenshots) : Too long Correct Too short

Honestly, I don't even know where to begin to solve that. Any pointers are welcome. Below is a WE/MWE:

\setuppapersize[S6]

\setuplayout[headerdistance=1cm]

\definemarking[subtitle]
\starttexdefinition slidetitle
  \marking [subtitle] {\structureuservariable{subtitle}}
\stoptexdefinition

% Defining the slides
\definehead[slide] [subject][
    page=yes,
    placehead=empty,
    insidesection=\slidetitle,
]
%Putting the slide title and subtile in a table (to get 2 bloody lines) inside the header
\setupheadertexts [{%
    \bTABLE[frame=no,align=middle,offset=0.05cm]
        \bTR \bTD {\getmarking [slide]} \eTD \eTR
        \bTR \bTD {\tfx\getmarking [subtitle]} \eTD \eTR
    \eTABLE
}]
\setupheader[text][style=\sc\ss\tfb]


\startuseMPgraphic {background}
StartPage;
    %Drawing the top lines. The variable w should be the max of the widths of the title and subtitle. So basically the width of the natural table containing them
    numeric w; path line;
    w=6cm;
    line:=((0,0) -- for i=1cm step 1cm until PaperWidth/2-w/2-1cm : (i,-uniformdeviate(0.7cm)) -- endfor (PaperWidth/2-w/2,-0.5cm) -- (PaperWidth/2+w/2,-0.5cm) -- for i=PaperWidth/2+w/2+1cm step 1cm until PaperWidth-1cm : (i,-uniformdeviate(0.7cm)) -- endfor (PaperWidth,0)) shifted (0,PaperHeight-1.8cm);
    drawpath line withpen pencircle scaled 1mm;
StopPage;
\stopuseMPgraphic

\defineoverlay [background][\reuseMPgraphic{background}]
\setupbackgrounds[page][background=background]


\starttext

\startslide[title={Hello}]
\input knuth
\stopslide

\startslide[title={Font examples}] [subtitle=a subtitle]
\input ward
\stopslide

\startslide[title={A very very long and detailed title}]
    [subtitle={As well as an inexcusably long and annoying subtitle}]
some text
\stopslide


\stoptext

Apologies if post doesn't respect some rule, not used to posting here.

  • 2
    I think you could use positionnal graphics, as defined in Metafun manual chapter 5. – sztruks Oct 12 at 10:34
  • Your MWE does not give the output of your screenshots. I edited it to have the third one printed, but you should either add your background elements or better sent screenshots that you get when compiling your MWE. – sztruks Oct 12 at 10:50
  • Oh, and btw, welcome to TeX S.E.! – sztruks Oct 12 at 11:01
  • Wow, that is exactly what I was looking for, guess I should read the manuals a bit more closely next time. Thank you very much! For the MWE, my bad, I stripped the document but forgot about it when making the screenshots :/ Thanks! – Semptum Valoris Oct 12 at 11:17
2

Answered by sztruks:

I think you could use positional graphics, as defined in Metafun manual chapter 5.

EDIT: What I get using positional graphics is not exactly right. I assign an \hpos to the title-subtitle bundle and get its width. Unfortunately, as far as I understand, \startMPpositiongraphic is only calculated after the whole document has been typeset, at which point the \hpos only refers to the title-subtitle of the very last page. As a result, the lines are not drawn on all but the last page. There however they are drawn with the right dimensions.

EDIT2: Solved by simply putting value of counter in hpos (specifically \userpagenumber) as well as putting the \start/stoppositionoverlay code inside some function executed at each slide (so that the counter gets updated, otherwise only the first page gets a drawing). Not posting new pictures since the one below already describes what I get.

Marking the question as answered.

Here is what I now have:

\setuppapersize[S6]

\setuplayout[headerdistance=1cm]

\definemarking[subtitle]
\starttexdefinition slidetitle
    \marking [subtitle] {\structureuservariable{subtitle}}
    \startpositionoverlay{posover:background}
        \setMPpositiongraphic{titles-\userpagenumber}{background}{self=titles-\userpagenumber}
    \stoppositionoverlay
\stoptexdefinition

% Defining the slides
\definehead[slide] [subject][
    page=yes,
    placehead=empty,
    insidesection=\slidetitle,
]
%Putting the slide title and subtile in a table (to get 2 bloody lines) inside the header
\setupheadertexts [\hpos{titles-\userpagenumber}{%
    \bTABLE[frame=no,align=middle,offset=0.05cm]
        \bTR \bTD {\getmarking [slide]} \eTD \eTR
        \bTR \bTD {\tfx\getmarking [subtitle]} \eTD \eTR
    \eTABLE
}]
\setupheader[text][style=\sc\ss\tfb]


\startMPpositiongraphic {background}
StartPage;
    %Drawing the top lines. The variable w should be the max of the widths of the title and subtitle. So basically the width of the natural table containing them
    numeric w; path line;
    w=\MPw{\MPvar{self}} ;
    line:=((0,0) -- for i=1cm step 1cm until PaperWidth/2-w/2-1cm : (i,-uniformdeviate(0.7cm)) -- endfor (PaperWidth/2-w/2,-0.5cm) -- (PaperWidth/2+w/2,-0.5cm) -- for i=PaperWidth/2+w/2+1cm step 1cm until PaperWidth-1cm : (i,-uniformdeviate(0.7cm)) -- endfor (PaperWidth,0)) shifted (0,PaperHeight-1.8cm);
    drawpath line withpen pencircle scaled 1mm;
StopPage;
\stopMPpositiongraphic


\defineoverlay [over:background][\positionoverlay{posover:background}]
\setupbackgrounds[page][background=over:background]


\starttext

\startslide[title={Hello}]
\input knuth
\stopslide

\startslide[title={Font examples}] [subtitle=a subtitle]
\input ward
\stopslide

\startslide[title={A very very long and detailed title}]
    [subtitle={As well as an inexcusably long and annoying subtitle}]
some text
\stopslide


\stoptext

The result is this for the last page: You can notice the lines and titles are not exactly vertically aligned. It's not the case in the complete example. Too You can notice the lines and titles are not exactly vertically aligned. It's not the case in the complete example. Too tired to figure out why.

  • 1
    I did not really answer: the trouble is I'm not able to put this chapter into practice, because I’m not used to overlays yet. So I am looking forward to seeing how you solved the problem… – sztruks Oct 12 at 15:14
  • I am currently not on my computer so I can only read the chapter. I'll try to implement a solution tonight. But the chapter was exactly the link between content and position I was looking for, so I'm hopeful. – Semptum Valoris Oct 12 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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