2

I'm thinking about switching from LaTeX to ConTeXt. I'm using LaTeX extensively to create teaching materials with an extended version of xsim. There are a lot of things I would need to port, one of them is a macro which produces a number of lines as a writing area for students. In LaTeX I just draw a line with TikZ with \linewidth, which returns the width in the current environment (e.g. in an itemize environment). I tried to recreate this same behavior with ConTeXt / MetaPost(fun) and it works well with \textwidth which returns the full width, independent of the current environment. I could not find any reference to a equivalent of \linewidth in the documentations. Is there such a command or a possibility to get the current environments x position?

Here's a minimal example, I would need to replace \the\textwidth with something like \the\linewidth. There are other issues, like the justification of the text before the break, but this is something I may figure out later.

\setuppapersize[A4] 
\setupbodyfont[modern,12pt] 

\starttext

\startuseMPgraphic{line}
draw ((0cm,0cm)--(\the\textwidth,0cm)) ;
\stopuseMPgraphic

\startitemize
  \item here we list the points,\break\useMPgraphic{line}
  \item one after the other.
\stopitemize
\useMPgraphic{line}

\stopchapter
\stoptext

1 Answer 1

2

Welcome to the site. You can do this:

\startuseMPgraphic{line}
numeric hsize ; hsize = \the \ifzeropt\localhsize \hsize \else \localhsize \fi;

draw (0cm,0cm) -- (hsize,0cm);
\stopuseMPgraphic

But I think what you try to do is more easily done with fillinrules. I give an example below. There I have also removed the setup of paper (A4 is the default)

\setupbodyfont[modern, 12pt] 

\starttext

\startitemize
  \item here we list the points,
  \fillinrules[n=2]
  \item one after the other.
\stopitemize
\fillinrules[n=3]

\stoptext

example with lines

You can read more about fillinrules here.

1
  • 2
    Well, fillinrules makes it simple! Also, thanks a lot for the \hsize and \localhsize reference, this will help with some additional features, e.g. a rectangular, checked region instead a line!
    – debu
    Commented Apr 1, 2022 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .