ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Re: Equivalent to \settowidth
       [not found] <mailman.3259.1173955297.17432.ntg-context@ntg.nl>
@ 2007-03-17 12:39 ` Robin Kirkham
  2007-03-20 21:14   ` Peter Münster
  0 siblings, 1 reply; 6+ messages in thread
From: Robin Kirkham @ 2007-03-17 12:39 UTC (permalink / raw)
  To: ntg-context

> From: Hans Hagen <pragma@wxs.nl>
> Wolfgang Schuster wrote:
>> 2007/3/14, Robin Kirkham <robin.kirkham@csiro.au>:
>>>
>>> Is there a ConTeXt equivalent to LaTeX \settowidth{}, or better  
>>> still
>>> some macro I can do things like
>>>
>>> \setupsomething[
>>>      ...
>>>      width={\widthof{\bf sometext\emspace}},
>>>      ...]

> \def\setwidthof#1\to#2%
> {\bgroup
>  \setbox\scratchbox\hbox{#1}%
>  \expanded{\egroup\def\noexpand#2{\the\wd\scratchbox}}}

Thanks Wolfgang, Chen and Hans for your responses. I used Hans'  
one ... it seems to work.

I'm actually trying to indent tables of contents by level. I want  
each indent to match the start of the heading text of the previous  
level, i.e.,

1  Chapter
    1.1  Section
         1.1.1  Subsection
         1.1.2  Subsection
...
Title

in other words, the indent is not quite a fixed width per level.

The following complete example sort of does what I want (using Hans'  
\setwidthof) but it will fail when the section numbers have more  
digits than I have allowed for.
I have a feeling I should be using \setupcombinedlist[content] 
[distance=1em] or something, but that puts an em space in front of  
unnumbered chapters (titles) as well.

What I have done seems very ugly, surely there is a "proper" way?

Robin

% widthof macro from Hans
\def\setwidthof#1\to#2%
     {\bgroup
         \setbox\scratchbox\hbox{#1}%
         \expanded{\egroup\def\noexpand#2{\the\wd\scratchbox}}}

\setupcombinedlist[content][
     alternative=c,
     aligntitle=yes]
\setuplist[chapter][
     alternative=b,
     style=bold]

% calculate widths of numbers
\setwidthof{\bf 9\emspace}\to\WDA
\setwidthof{9.9\emspace}\to\WDB
\setwidthof{9.9.9\emspace}\to\WDC
\setwidthof{9.9.9.9\emspace}\to\WDD

% calculate margins
\setwidthof{{\bf 9\emspace}}\to\MAB
\setwidthof{{\bf 9\emspace}9.9\emspace}\to\MAC
\setwidthof{{\bf 9\emspace}9.9\emspace 9.9.9\emspace}\to\MAD

\setuplist[chapter]             [margin=0em,  width=\WDA]
\setuplist[section]             [margin=\MAB, width=\WDB]
\setuplist[subsection]          [margin=\MAC, width=\WDC]
\setuplist[subsubsection]       [margin=\MAD, width=\WDD]


\starttext

\completecontent[criterium=all]
\page

\startfrontmatter
\chapter{Unnumbered Chapter}
\stopfrontmatter

\startbodymatter
\chapter{Chapter}
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\subsubsection{Subsubsection}
\subsubsection{Subsubsection}
\subsubsection{Subsubsection}
\subsubsection{Subsubsection}
\subsubsection{Subsubsection}
\subsubsection{Subsubsection}
\subsubsection{Subsubsection}
\subsubsection{Subsubsection}
\subsubsection{Subsubsection}
\subsubsection{Subsubsection}
\chapter{Chapter}
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\chapter{Chapter}
\stopbodymatter

\stoptext

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Equivalent to \settowidth
  2007-03-17 12:39 ` Equivalent to \settowidth Robin Kirkham
@ 2007-03-20 21:14   ` Peter Münster
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Münster @ 2007-03-20 21:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Sat, 17 Mar 2007, Robin Kirkham wrote:

> The following complete example sort of does what I want (using Hans'
> \setwidthof) but it will fail when the section numbers have more
> digits than I have allowed for.
> I have a feeling I should be using \setupcombinedlist[content]
> [distance=1em] or something, but that puts an em space in front of
> unnumbered chapters (titles) as well.
> 
> What I have done seems very ugly, surely there is a "proper" way?

Hello Robin,

some time ago I made something similar. It's certainly not the "proper"
way, but much shorter:

\def\PageCommand#1{\hbox to 1em{\hss#1}}
\setupcombinedlist[content][alternative=c,pagecommand=\PageCommand,
  aligntitle=yes]
\setuplist[chapter][style=bold,alternative=b,width=1.5em]
\setuplist[section][margin=1.5em,width=2em]
\setuplist[subsection][margin=3.5em,width=3em]
\setuplist[subsubsection][margin=6.5em,width=4em]

Cheers, Peter

-- 
http://pmrb.free.fr/contact/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Equivalent to \settowidth
  2007-03-14 10:40 ` Wolfgang Schuster
@ 2007-03-14 12:06   ` Hans Hagen
  0 siblings, 0 replies; 6+ messages in thread
From: Hans Hagen @ 2007-03-14 12:06 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Wolfgang Schuster wrote:
> 2007/3/14, Robin Kirkham <robin.kirkham@csiro.au>:
>
>> Hi all,
>>
>> Is there a ConTeXt equivalent to LaTeX \settowidth{}, or better still
>> some macro I can do things like
>>
>> \setupsomething[
>>      ...
>>      width={\widthof{\bf sometext\emspace}},
>>      ...]
>>
>> Cheers,
>>
>> Robin
>
>
> Hi Robin,
>
> I don't know if there is something build in but the following definition
> should
> work for simple cases.
>
> \def\widthof#1%
>  {\bgroup
>   \setbox\scratchbox\hbox{#1}%
>   \the\wd\scratchbox%
>   \egroup}
>
> \starttext
>
> \getrawparameters
>  [robin]
>  [width=\widthof{Robin Kirkham}]
>
> \robinwidth
>
> \stoptext
>

this will typeset ok, but not with \dimen0=\robinwidth

\def\setwidthof#1\to#2%
 {\bgroup
  \setbox\scratchbox\hbox{#1}%
  \expanded{\egroup\def\noexpand#2{\the\wd\scratchbox}}}

\starttext

\setwidthof{Robin Kirkham}\to\whatever

\getrawparameters
 [robin]
 [width=\whatever]

\robinwidth

or so (untested)


-- 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Equivalent to \settowidth
  2007-03-14 10:05 Robin Kirkham
  2007-03-14 10:38 ` Zhichu Chen
@ 2007-03-14 10:40 ` Wolfgang Schuster
  2007-03-14 12:06   ` Hans Hagen
  1 sibling, 1 reply; 6+ messages in thread
From: Wolfgang Schuster @ 2007-03-14 10:40 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 603 bytes --]

2007/3/14, Robin Kirkham <robin.kirkham@csiro.au>:

> Hi all,
>
> Is there a ConTeXt equivalent to LaTeX \settowidth{}, or better still
> some macro I can do things like
>
> \setupsomething[
>      ...
>      width={\widthof{\bf sometext\emspace}},
>      ...]
>
> Cheers,
>
> Robin


Hi Robin,

I don't know if there is something build in but the following definition
should
work for simple cases.

\def\widthof#1%
  {\bgroup
   \setbox\scratchbox\hbox{#1}%
   \the\wd\scratchbox%
   \egroup}

\starttext

\getrawparameters
  [robin]
  [width=\widthof{Robin Kirkham}]

\robinwidth

\stoptext

Wolfgang

[-- Attachment #1.2: Type: text/html, Size: 1102 bytes --]

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

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Equivalent to \settowidth
  2007-03-14 10:05 Robin Kirkham
@ 2007-03-14 10:38 ` Zhichu Chen
  2007-03-14 10:40 ` Wolfgang Schuster
  1 sibling, 0 replies; 6+ messages in thread
From: Zhichu Chen @ 2007-03-14 10:38 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 950 bytes --]

Hi, Robin

I think you can include the texts in an \hbox and use \wd?? to get its width


On 3/14/07, Robin Kirkham <robin.kirkham@csiro.au> wrote:
>
> Hi all,
>
> Is there a ConTeXt equivalent to LaTeX \settowidth{}, or better still
> some macro I can do things like
>
> \setupsomething[
>      ...
>      width={\widthof{\bf sometext\emspace}},
>      ...]
>
> Cheers,
>
> Robin
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context
>



-- 
Sincerely yours,
Chen
----------------------------------------------------------------

          Zhi-chu Chen | Shanghai Synchrotron Radiation Facility
         No. 2019 | Jialuo Rd. | Jiading | Shanghai | P.R. China
             tel: 086 21 5955 3405 | zhichu.chen.googlepages.com
                                               | www.sinap.ac.cn
----------------------------------------------------------------

[-- Attachment #1.2: Type: text/html, Size: 1951 bytes --]

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

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Equivalent to \settowidth
@ 2007-03-14 10:05 Robin Kirkham
  2007-03-14 10:38 ` Zhichu Chen
  2007-03-14 10:40 ` Wolfgang Schuster
  0 siblings, 2 replies; 6+ messages in thread
From: Robin Kirkham @ 2007-03-14 10:05 UTC (permalink / raw)
  To: ntg-context

Hi all,

Is there a ConTeXt equivalent to LaTeX \settowidth{}, or better still  
some macro I can do things like

\setupsomething[
      ...
      width={\widthof{\bf sometext\emspace}},
      ...]

Cheers,

Robin

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-03-20 21:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <mailman.3259.1173955297.17432.ntg-context@ntg.nl>
2007-03-17 12:39 ` Equivalent to \settowidth Robin Kirkham
2007-03-20 21:14   ` Peter Münster
2007-03-14 10:05 Robin Kirkham
2007-03-14 10:38 ` Zhichu Chen
2007-03-14 10:40 ` Wolfgang Schuster
2007-03-14 12:06   ` Hans Hagen

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).