ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: mf <massifr@fastwebnet.it>
To: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>,
	mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: changing alignment inside a paragraph
Date: Thu, 12 Dec 2019 15:56:27 +0100	[thread overview]
Message-ID: <f2bee7f0-e281-b64e-05a6-c701dbd6c03d@fastwebnet.it> (raw)
In-Reply-To: <e598f261-0f6e-911e-038f-1e364a0a47e4@gmail.com>

Il 11/12/19 21:25, Wolfgang Schuster ha scritto:
> \starttext
> 
> \startbuffer
> This is the text of an index term, that is normally justified,
> but I'd like the page numbers to be flushed to the right from
> their second line\par
> \startalignment[flushright]
> \ifdim\dimexpr\hsize-\lastlinewidth\relax>2\emwidth
>      \blank[overlay]
> %   simple solution but doesn't indent the numbers on the following lines
> %   \hskip\dimexpr\lastlinewidth+\emwidth\relax
>      \parshape 2
>          \dimexpr\lastlinewidth+\emwidth\relax 
> \dimexpr\hsize-\lastlinewidth-\emwidth\relax
>          \emwidth \dimexpr\hsize-\emwidth\relax
> \else
>      \parshape 1 \emwidth \dimexpr\hsize-\emwidth\relax
> \fi
> 34, 57, 101-104, 276, 345, 401, 403, 512.
> \stopalignment
> \stopbuffer
> 
> \dorecurse
>    {10}
>    {\hsize\dimexpr.75\textwidth-#1\emwidth\relax
>     \getbuffer
>     \page}
> 
> \stoptext
> 

Thanks Wolfgang.

I wrote a better version. I still have a couple of questions.
In the lines:

\iffirstargument
   \getparameters[PIT!][test=off,margin=1em,distance=1em,minwidth=1em,#1]
\else
   \getparameters[PIT!][test=off,margin=1em,distance=1em,minwidth=1em,]
\fi

i would avoid writing the default values twice; i tried something like:

\getparameters[PIT!][test=off,margin=1em,distance=1em,minwidth=1em,\iffirstargument#1\fi]

but it doesn't work.

For the second question, see the first item of page 3: i think the 
\lastlinewidth fails because there's a page break. From supp-box.lua:

implement {
     name    = "lastlinewidth",
     actions = function()
         local head = tex.lists.page_head
         -- list dimensions returns 3 value but we take the first
         context(head and 
getdimensions(getlist(find_tail(tonut(tex.lists.page_head)))) or 0)
     end
}

I think that's because page_head is reset in the page break.
Is there a way to prevent that?

Massi

--------------------------------------------------------------
\unprotect
\def\PlaceIndexTerm{\dosingleempty\doPlaceIndexTerm}
\def\doPlaceIndexTerm[#1]#2#3{%
\iffirstargument
   \getparameters[PIT!][test=off,margin=1em,distance=1em,minwidth=1em,#1]
\else
   \getparameters[PIT!][test=off,margin=1em,distance=1em,minwidth=1em,]
\fi
#2\par
\startalignment[flushright,stretch]
\ifdim\dimexpr\hsize-\lastlinewidth\relax > 
\dimexpr\PIT!distance+\PIT!minwidth\relax
   \blank[overlay]
   \parshape 2
   \dimexpr\lastlinewidth+\PIT!distance\relax 
\dimexpr\hsize-\lastlinewidth-\PIT!distance\relax
   \PIT!margin \dimexpr\hsize-\PIT!margin\relax \doif{\PIT!test}{on}{\red}
\else
   \page[no]
   \parshape 1 \PIT!margin \dimexpr\hsize-\PIT!margin\relax 
\doif{\PIT!test}{on}{\darkgreen}
\fi
#3\par
\stopalignment}
\protect

\setupalign[stretch]

\starttext

\def\Text{This is the text of an index term, that is normally justified,
but I'd like the page numbers to be flushed to the right from
their second line}

\def\Pages{34, 57, 101-104, 276, 345, 401, 403, 512.}

\type{\PlaceIndexTerm[margin=1em,distance=1em,minwidth=1em]{text}{pages}}
\startitemize
\item margin:
       the left margin of the lines made only of page numbers
\item distance:
       the distance of the first page number from the last word of the text
\item minwidth:
       the shortest acceptable space at the end of the text to try to 
start page numbers there
\stopitemize

\page

\dorecurse
   {23}
   {\hsize=\dimexpr5cm+#1\emwidth\relax
    #1: \the\hsize\par
    \PlaceIndexTerm[test=on]{\Text}{\Pages}}

\stoptext
--------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2019-12-12 14:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-10 11:27 mf
2019-12-10 17:07 ` Wolfgang Schuster
2019-12-11 14:31 ` mf
2019-12-11 20:25   ` Wolfgang Schuster
2019-12-12 14:56     ` mf [this message]
2019-12-12 20:43       ` Wolfgang Schuster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f2bee7f0-e281-b64e-05a6-c701dbd6c03d@fastwebnet.it \
    --to=massifr@fastwebnet.it \
    --cc=ntg-context@ntg.nl \
    --cc=wolfgang.schuster.lists@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).