* changing alignment inside a paragraph @ 2019-12-10 11:27 mf 2019-12-10 17:07 ` Wolfgang Schuster 2019-12-11 14:31 ` mf 0 siblings, 2 replies; 6+ messages in thread From: mf @ 2019-12-10 11:27 UTC (permalink / raw) To: mailing list for ConTeXt users Hello list, is there a way to achieve this? \def\FlushRightFromNextLine{\relax} \setupnarrower[left=0cm,right=11cm] \setupalign[stretch] \starttext This is what I'd like to type in my source:\par \blank \type{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 \FlushRightFromNextLine 34, 57, 101-104, 276, 345, 401-403.}\par \blank This is the normal result:\par \blank \startnarrower[right] 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 \FlushRightFromNextLine 34, 57, 101-104, 276, 345, 401-403. \stopnarrower \blank This is the expected result:\par \blank \startnarrower[right] \parfillskip=0pt 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 34, 57,\par \penalty10000 % no page break in the middle of page numbers \startalignment[flushright] 101-104, 276, 345, 401-403.\par \stopalignment \stopnarrower \stoptext The expected result is to be intended visually, because there might be no need to break the text into two paragraphs. Thanks, Massi ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: changing alignment inside a paragraph 2019-12-10 11:27 changing alignment inside a paragraph mf @ 2019-12-10 17:07 ` Wolfgang Schuster 2019-12-11 14:31 ` mf 1 sibling, 0 replies; 6+ messages in thread From: Wolfgang Schuster @ 2019-12-10 17:07 UTC (permalink / raw) To: mailing list for ConTeXt users, mf mf schrieb am 10.12.2019 um 12:27: > Hello list, is there a way to achieve this? > > \def\FlushRightFromNextLine{\relax} > \setupnarrower[left=0cm,right=11cm] > \setupalign[stretch] > \starttext > This is what I'd like to type in my source:\par > \blank > \type{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 \FlushRightFromNextLine 34, 57, 101-104, 276, 345, > 401-403.}\par > \blank > This is the normal result:\par > \blank > \startnarrower[right] > 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 \FlushRightFromNextLine 34, 57, 101-104, 276, 345, > 401-403. > \stopnarrower > \blank > This is the expected result:\par > \blank > \startnarrower[right] > \parfillskip=0pt 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 34, 57,\par > \penalty10000 % no page break in the middle of page numbers > \startalignment[flushright] > 101-104, 276, 345, 401-403.\par > \stopalignment > \stopnarrower > \stoptext > > The expected result is to be intended visually, because there might be > no need to break the text into two paragraphs. Use the "end" keyword for the alignment. \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 34, 57, 101-104, 276, 345, 401–403. \stopbuffer \typebuffer \getbuffer \startbuffer \startalignment[end] 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 34, 57, 101-104, 276, 345, 401–403. \stopalignment \stopbuffer \typebuffer \getbuffer \stoptext Wolfgang ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: changing alignment inside a paragraph 2019-12-10 11:27 changing alignment inside a paragraph mf 2019-12-10 17:07 ` Wolfgang Schuster @ 2019-12-11 14:31 ` mf 2019-12-11 20:25 ` Wolfgang Schuster 1 sibling, 1 reply; 6+ messages in thread From: mf @ 2019-12-11 14:31 UTC (permalink / raw) To: mailing list for ConTeXt users This is a good-enough solution to my problem: \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} has 6 parameters: \startitemize[n] \item the main text \item the pages' numbers \item the text width \item the left margin of the lines made only of page numbers \item the width of the separator (an hbox) before the first page number, when there's room in the last line of the text \item the minimum accepted space left at the end of the last line of text, to put a page number \stopitemize \def\PlaceIndexTerm#1#2#3#4#5#6{% \newdimen\TextWidth \TextWidth=#3 \newdimen\SBPN \SBPN=#5 % space before page numbers \newdimen\PagesIndentation \PagesIndentation=#4 \newdimen\MSLLL \MSLLL=#6 % minimum space left on last line \parshape 1 0pt \TextWidth #1\par \newdimen\LLW \LLW=\lastlinewidth \page[no] \ifdim \dimexpr\TextWidth-\LLW-\SBPN > \MSLLL \blank[-\the\lineheight,fixed]\fi \startalignment[flushright,stretch] \ifdim \dimexpr\TextWidth-\LLW-\SBPN > \MSLLL \parshape 2 \LLW \dimexpr \TextWidth - \LLW \PagesIndentation \dimexpr \TextWidth - \PagesIndentation \red \else \parshape 1 \PagesIndentation \dimexpr \TextWidth - \PagesIndentation \darkgreen \fi \noindent\ifdim \dimexpr\TextWidth-\LLW-\SBPN > \MSLLL\hbox to \SBPN{}\fi #2\par \stopalignment} \def\PlaceIndexTermDescribed#1#2#3#4#5#6{% \newdimen\TW\TW=#3 \noindent{\tfx width={\bf \PtToCm{\the\TW}}, pages' left margin (2nd line)={\bf #4}, hbox before pages={\bf #5},\\% min space left on last line of text={\bf #6}}\par \blank[halfline] \PlaceIndexTerm{#1}{#2}{#3}{#4}{#5}{#6} \blank} \page \PlaceIndexTermDescribed{\Text}{\Pages}{3cm}{12pt}{1em}{12pt} In this case there's no space left on the last line of text, so the page numbers are flushed to the right, starting from a new line. \page \PlaceIndexTermDescribed{\Text}{\Pages}{3.5cm}{12pt}{1em}{12pt} Now the last line of text is short and there's room to start the page numbers on the same line. The remainder of page numbers is flushed right, with a (min) left margin of 12pt.\par Actually, the page numbers are started in a new paragraph with a \type{\parshape} that depends on the last line of the text; then the new paragraph is moved upwards with a \type{\blank[-\the\lineheight,fixed]}. A \type{\page[no]} before the \type{\blank} guarantees that no page break occurs between text and numbers. \page \PlaceIndexTermDescribed{\Text}{\Pages}{4cm}{12pt}{1em}{12pt} \page \PlaceIndexTermDescribed{\Text}{\Pages}{4.5cm}{12pt}{1em}{12pt} \page \PlaceIndexTermDescribed{\Text}{\Pages}{5cm}{12pt}{1em}{12pt} \page \PlaceIndexTermDescribed{\Text}{\Pages}{5.5cm}{12pt}{1em}{12pt} \page \PlaceIndexTermDescribed{\Text}{\Pages}{6cm}{12pt}{1em}{12pt} \page \PlaceIndexTermDescribed{\Text}{\Pages}{6.5cm}{12pt}{1em}{12pt} \page \PlaceIndexTermDescribed{\Text}{\Pages}{7cm}{12pt}{1em}{12pt} \page \PlaceIndexTermDescribed{\Text}{\Pages}{7.5cm}{12pt}{1em}{12pt} \page \PlaceIndexTermDescribed{\Text}{\Pages}{8cm}{12pt}{1em}{12pt} That \type{512} left on the last line is ugly, and we can trim the separator hbox from \type{1em} to \type{.1em} to let all the page numbers fit in the last line:\par \blank \PlaceIndexTermDescribed{\Text}{\Pages}{8cm}{12pt}{.1em}{12pt} or we could increase the left margin of the lines made only of page numbers (to \type{3cm} in this case), to distribute the numbers better across the two lines:\par \blank \PlaceIndexTermDescribed{\Text}{\Pages}{8cm}{3cm}{1em}{12pt} \page \PlaceIndexTermDescribed{\Text}{\Pages}{8.5cm}{12pt}{1em}{12pt} \page \PlaceIndexTermDescribed{\Text}{\Pages}{9cm}{12pt}{1em}{12pt} \page \PlaceIndexTermDescribed{\Text}{\Pages}{9.5cm}{12pt}{1em}{12pt} Increasing the left margin of the lines of page numbers gives a better result:\par \blank \PlaceIndexTermDescribed{\Text}{\Pages}{9.5cm}{4cm}{1em}{12pt} \page Full text width (third parameter set to \type{\textwidth}):\par \blank \PlaceIndexTermDescribed{\Text}{\Pages}{\textwidth}{12pt}{1em}{12pt} \stoptext (Thanks again to Wolfgang for answering my question) Massi ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: changing alignment inside a paragraph 2019-12-11 14:31 ` mf @ 2019-12-11 20:25 ` Wolfgang Schuster 2019-12-12 14:56 ` mf 0 siblings, 1 reply; 6+ messages in thread From: Wolfgang Schuster @ 2019-12-11 20:25 UTC (permalink / raw) To: mailing list for ConTeXt users, mf mf schrieb am 11.12.2019 um 15:31: > This is a good-enough solution to my problem: > > \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} has 6 parameters: > \startitemize[n] > \item the main text > \item the pages' numbers > \item the text width > \item the left margin of the lines made only of page numbers > \item the width of the separator (an hbox) before the first page > number, when there's room > in the last line of the text > \item the minimum accepted space left at the end of the last line of > text, to put a page number > \stopitemize > > \def\PlaceIndexTerm#1#2#3#4#5#6{% > \newdimen\TextWidth \TextWidth=#3 > \newdimen\SBPN \SBPN=#5 % space before page numbers > \newdimen\PagesIndentation \PagesIndentation=#4 > \newdimen\MSLLL \MSLLL=#6 % minimum space left on last line > \parshape 1 0pt \TextWidth #1\par > \newdimen\LLW \LLW=\lastlinewidth > \page[no] > \ifdim \dimexpr\TextWidth-\LLW-\SBPN > \MSLLL > \blank[-\the\lineheight,fixed]\fi > \startalignment[flushright,stretch] > \ifdim \dimexpr\TextWidth-\LLW-\SBPN > \MSLLL > \parshape 2 > \LLW \dimexpr \TextWidth - \LLW > \PagesIndentation \dimexpr \TextWidth - \PagesIndentation \red > \else > \parshape 1 \PagesIndentation \dimexpr \TextWidth - \PagesIndentation > \darkgreen > \fi > \noindent\ifdim \dimexpr\TextWidth-\LLW-\SBPN > \MSLLL\hbox to > \SBPN{}\fi #2\par > \stopalignment} \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 Wolfgang ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: changing alignment inside a paragraph 2019-12-11 20:25 ` Wolfgang Schuster @ 2019-12-12 14:56 ` mf 2019-12-12 20:43 ` Wolfgang Schuster 0 siblings, 1 reply; 6+ messages in thread From: mf @ 2019-12-12 14:56 UTC (permalink / raw) To: Wolfgang Schuster, mailing list for ConTeXt users 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: changing alignment inside a paragraph 2019-12-12 14:56 ` mf @ 2019-12-12 20:43 ` Wolfgang Schuster 0 siblings, 0 replies; 6+ messages in thread From: Wolfgang Schuster @ 2019-12-12 20:43 UTC (permalink / raw) To: mf; +Cc: mailing list for ConTeXt users mf schrieb am 12.12.2019 um 15:56: > 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. Skip the argument check and use just this: \getparameters[PIT!][test=off,margin=1em,distance=1em,minwidth=1em,#1] Wolfgang ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-12-12 20:43 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-12-10 11:27 changing alignment inside a paragraph 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 2019-12-12 20:43 ` Wolfgang Schuster
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).