Prolozene pismo

Jan Holub holub at fel.cvut.cz
Mon Apr 19 18:46:50 CEST 2004


	Dobry den,
potreboval bych do textu dostat prolozene pismo. Vim, ze se mu ma clovek
vyhnout, ale v mem pripade je to zavedena konvence.

Kdyz jsem zkusil nekolik verzi balicku lettersp* (viz prilozene zdrojaky),
tak se sice prolozene pismo objevilo, ale nechtelo se mrcha zalomit a
psalo to ten prolozeny text do jednoho nekonecneho radku. Balicek
letterspace.sty mi dokonce hlasi "Argument of \m at kespaceexplicit has an
extra }.". (BTW: Maji se tady opravdu psat obe ty tecky?)

Kdysi jsem zkousel i makro \prostrkej od pana Olsaka (TeXbook naruby,
TBN). To sice zalamovalo radky, ale nekdy taky ne. Tedka mi to hlasi na
^^X neznamy znak (viz chybovy vypis dole; Nevite nekdo co s tim?), takze
ho ani nemuzu vyzkouset. Soubor prostrkej.sty obsahuje presne radky
189-206 z TBN str. 106. Drive jsem to delal pro EmTeX a ted pro pocesteny
tetex-1.0.7-66 (RedHat Linux 9).

V TBN mi pak p. Olsak radi, ze pokud bych chtel i deleni slov, musim na to
jit pres virtualni fonty, kteryzto pojem je pro mne jako vlasovy vstavac.

	Predem dekuji za rady, napady, popr. nasmerovani,

						JH

---------------------------------------------------------------------------
$ cslatex Prolozene.tex && dvips Prolozene
This is TeX, Version 3.14159 (Web2C 7.3.1)
(/usr/share/texmf/web2c/il2-cs.tcx)
(Prolozene.tex
LaTeX2e <2001/06/01>
Loading CZ hyphenation patterns: Pavel Sevecek, v3, 1995
Loading SK hyphenation patterns: Jana Chlebikova, 1992
(/usr/share/texmf/tex/latex/base/article.cls
Document Class: article 2001/04/21 v1.4e Standard LaTeX document class
(/usr/share/texmf/tex/latex/base/size10.clo)) (prostrkej.sty
! Text line contains an invalid character.
l.4 ...oup\let\pp=\relax\let\next=\strk \strk#1^^X
                                                  }
? x
No pages of output.
Transcript written on Prolozene.log.

-------------- next part --------------
\documentclass[twoside,a4paper,twocolumn]{article}
%\input{letterspacing} % 1. metoda
%\input{lettersp} % 2. metoda
\usepackage{letterspace} % 3. metoda
%\usepackage{prostrkej} % 4. metoda
\usepackage{latexsym}
\usepackage{czech}

% 1.-3. metoda
\newcommand\prolozrm[1]{{\letterspace to 1.3\naturalwidth {#1} } }
\newcommand\prolozbf[1]{\textbf{\letterspace to 1.5\naturalwidth {#1} } }

% 4. metoda
%\newcommand\prolozrm[1]{{\prostrkej{#1} } }
%\newcommand\prolozbf[1]{\textbf{\prostrkej{#1} } }

\begin{document}
Neprolo?en? a za n?m prolo?en? \prolozrm{j? vsad?m se, j? tvrd?m, to je tak, to je pravda} a u? zase neprolo?en?

Neprolo?en? a za n?m prolo?en? \prolozbf{j? vsad?m se, j? tvrd?m, to je tak, to je pravda} a u? zase neprolo?en?
\end{document}
-------------- next part --------------
% Self-documenting file

\ifx  \Comment \Undefined
      \long \def \Comment #1\EndComment {}
\else
      \ifx  \EndComment \Undefined
            \def \EndComment
                {\message {Error: \noexpand \EndComment encountered
                                without preceding \noexpand \Comment}}
      \else %%% both defined; let's hope they're the right definitions!
      \fi
\fi

\Comment
This file, "letterspacing.tex", created by Philip Taylor of RHBNC
(P.Taylor at Mail.Rhbnc.Ac.Uk) for Kaveh Bazargan of Focal Image
(Kaveh at Focal.Demon.Co.Uk) may be freely distributed provided that
no changes whatsoever are made to its contents
\EndComment

\Comment
As far as is possible, `inaccessible' control sequences (i.e.~control sequences
containing one or more commercial-at$\,$s) are used to minimise the risk of
accidental collision with user-defined macros; however, the control sequences
used to access the natural dimensions of the text are required to be user
accessible, and therefore must contain only letters.
\EndComment

%%% Open control sequences

\newdimen \naturalwidth
\newdimen \naturaldepth
\newdimen \naturalheight

\Comment
All control sequences defined hereafter are inaccessible to the casual user,
including the control sequence used to store the category code of commercial-at;
this catcode must be saved in order to be able to re-instate it at end of
module, as we have no idea in what context the module will be |\input|. Having
saved the catcode of commercial-at, we then change it to |11| (i.e.~that of a
letter) in order to allow it to be used in the cs-names which follow.
\EndComment

%%% Concealed control sequences

\expandafter \chardef
        \csname \string @code\endcsname =
                \the \catcode `\@
\catcode `\@ = 11

\Comment
We will need a a box register in order to measure the natural dimensions of
the text, and a token-list register in which to save the tokens to be
letter-spaced.
\EndComment

\newbox \l at tterspacebox
\newtoks \l at tterspacetoks

\Comment
We will need to test whether a particular macro expands to a space, so we will
need another macro which does so expand with which to compare it; we will
also need a `more infinite' variant of |\hss|.
\EndComment

\def \sp at ce { }
\def \hsss
    {\hskip 0 pt plus 1 fill minus 1 fill\relax}

\Comment
Many of the macros will used delimited parameter structures, typically
terminated by the reserved control sequence |\@nd|; we make this a synonym
for the empty macro (which expands to nothing), so that should it accidentally
get expanded there will be no side effects.  We also define a brief synonym
for |\expandafter|, just to keep the individual lines of code reasonably short.
\EndComment

\let \@nd = \empty
\let \@x = \expandafter

\Comment
We will also need to compare a token which has been peeked at by |\futurelet|
with a space token; because of the difficulty of accessing such a space
token (which would usually be absorbed by a preceding control word), we
establish |\sp at cetoken| as a synonym.  The code to achieve this is messy,
because of the very difficulty just outlined, and so we `waste' a control
sequence |\t at mp|; we then return this to the pool of undefined tokens.
\EndComment

\let \sp at cetoken = \relax
\edef \t at mp {\let \sp at cetoken = \sp at ce}
\t at mp \let \t at mp = \undefined

\Comment
The user-level macro |\letterspace| has exactly the same syntax as that for
|\hbox| and |\vbox|, as explained in the introduction; the delimited parameter
structure for this macro ensures that everything up to the open brace which
delimits the beginning of the text to be letter-spaced is absorbed as parameter
to the macro, and the brace-delimited text which follows is then assigned to the
token-list register |\l at tterspacetoks|; |\afterassignment| is used to regain
control once the assignment is complete.
\EndComment

%%% Primary (user-level) macro

\def \letterspace #1#%
    {\def \hb at xmodifier {#1}%
     \afterassignment \l at tterspace
     \l at tterspacetoks =
    }

\Comment
Control then passes to |\l at tterspace|, which starts by setting an |\hbox|
containing the text to be typeset; the dimensions of this box (and therefore
of the text) are then saved in the open control sequences previously declared,
and the |\hbox| becomes of no further interest.

A new |\hbox| is now created, in which the same text, but this time
letter-spaced, will be set; the box starts and ends with |\hss| glue so that if
only a single character is to be letter-spaced, it will be centered in the box.
If two or more characters are to be letter-spaced, they will be separated by
|\hsss| glue, previously declared, which by virtue of its greater degree of
infinity will completely override the |\hss| glue at the beginning and end;
thus the first and last characters will be set flush with the edges of the box.

The actual mechanism by which letter-spacing takes place is not yet apparent,
but it will be seen that it is crucially dependent on the definition of
|\l at tt@rspace|, which is expanded as the box is being set; the |\@x|
(|\expandafter|) causes the actual tokens stored in |\l at tterspacetoks| to be
made available as parameter to |\l at tt@rspace| rather than the token-list
register itself, as it is these tokens on which |\l at tt@rspace| will operate.
The |\@nd| terminates the parameter list, and the |{}| which immediately
precedes it ensures that that there is always a null element at the end of the
list: without this, the braces which are needed to protect an accent/character
pair would be lost if such a pair formed the final element of the list, at the
point where they are passed as the second (delimited) parameter to |\p at rtiti@n|;
by definition, <TeX> removes the outermost pair of braces from both simple and
delimited parameters during parameter substitution if such braces form the first
and last tokens of the parameter, and thus if a brace-delimited group ever
becomes the second element of a two-element list, the braces will be irrevocably
lost.  The |{}| ensure that such a situation can never occur.
\EndComment

%%% Secondary (implementation-level) macro

\def \l at tterspace
    {\setbox \l at tterspacebox = \hbox
                {\the \l at tterspacetoks}%
     \naturalwidth =  \wd \l at tterspacebox
     \naturaldepth =  \dp \l at tterspacebox
     \naturalheight = \ht \l at tterspacebox
     \hbox \hb at xmodifier
     \bgroup
           \hss
           \@x \l at tt@rspace
           \the \l at tterspacetoks {}\@nd
           \hss
     \egroup
    }

\Comment
The next macro is |\l at tt@rspace|, which forms the crux of the entire operation.
The text to be letter-spaced is passed as parameter to this macro, and the
first step is to check whether there is, in fact, any such text; this is
necessary both to cope with pathological usage (e.g.~|\letterspace {}|), and to
provide an exit route, as the macro uses tail-recursion to apply itself
iteratively to the `tail' of the text to be letter-spaced; when no elements
remain, the macro must exit.

Once the presence of text has been ensured, the token-list representing
this text is partitioned into a head (the first element), and the tail
(the remainder);  at each iteration, only the head is considered, although
if the tail is empty (i.e.~the end of the list has been reached), special
action is taken.

If the first element is a space, it is treated specially by surrounding it
with two globs of |\hsss| glue, to provide extra stretchability when compared
to the single glob of |\hsss| glue which will separate consecutive non-space
tokens; otherwise, the element itself is yielded, followed by a single glob
of |\hsss| glue.  This glue is suppressed if the element is the last of the
list, to ensure that the last token aligns with the edge of the box.

When the first element has been dealt with, the macro uses tail
recursion to apply itself to the remaining elements (i.e.~to the tail);
|\@x| (|\expandafter|) is again used to ensure that the tail is expanded
into its component tokens before being passed as parameter.
\EndComment

%%% Tertiary (implementation-level) macro

\def \l at tt@rspace #1\@nd
    {\ifx  \@nd #1\@nd
           \let \n at xt = \relax
     \else
           \p at rtition #1\@nd
           \ifx \h at ad \sp at ce \hsss \h at ad \hsss
           \else
                \h at ad
                \ifx \t at il \@nd \else \hsss \fi
           \fi
           \@x \def \@x \n at xt \@x
                {\@x \l at tt@rspace \t at il \@nd}%
     \fi
     \n at xt
    }

\Comment
The operation of token-list partitioning is conceptually simple: one passes the
token list as parameter text to a macro defined to take two parameters, the
first simple and the second delimited; the first element of the list will be
split off as parameter-1, and the remaining material passed as parameter-2.
Unfortunately this na\"\i ve approach fails when the first element is a bare
space, as the semantics of <TeX> prevent such a space from ever being passed as
a simple parameter (it could be passed as a delimited parameter, but as one
does not know what token follows the space, defining an appropriate delimiter
structure would be tricky if not impossible).  The technique used here relies
upon the adjunct macro |\m at kespacexplicit|, which replaces a leading bare space
by a space protected by braces; such spaces may legitimately be passed as simple
parameters.  Once that operation has been completed, the re-constructed token
list is passed to |\p at rtiti@n|, which actually performs the partitioning as
above; again |\@x| (|\expandafter|) is used to expand |\b at dy| (the
re-constructed token list) into its component elements before being passed as
parameter text.
\EndComment

%%% Adjunct macros -- list partitioning

\def \p at rtition #1\@nd
    {\m at kespacexplicit #1\@nd
     \@x \p at rtiti@n \b at dy \@nd
    }

\def \p at rtiti@n #1#2\@nd
    {\def \h at ad {#1}%
     \def \t at il {#2}%
    }

\Comment
The operation of making a space explicit relies on prescience: the code needs
to know what token starts the token list before it knows how to proceed.
Prescience in <TeX> is usually accomplished by |\futurelet|, and this code
is no exception: |\futurelet| here causes |\h at ad| to be |\let| equal to
the leading token, and control is then ceded to |\m at kesp@cexplicit|.

The latter compares |\h at ad| with |\sp at cetoken| (remember the convolutions we
had to go through to get |\sp at cetoken| correctly defined in the first place),
and if they match (i.e.~if the leading token is a space), then |\b at dy|
(the control sequence through which the results of this operation will
be returned) is defined to expand to a protected space (a space surrounded by
braces), followed by the remainder of the elements; if they do not match
(i.e.~if the leading token is \stress {not} a space), then |\b at dy| is simply
defined to be the original token list, unmodified.  If the leading token
\stress {was} a space, it must be replaced by a protected space: this is
accomplished by |\pr at tectspace|.

The |\pr at tectspace| macro uses a delimited parameter structure, as do most
of the other macros in this suite, but the structure used here is unique,
in that the initial delimiter is a space.  Thus, when a token-list starting
with a space is passed as parameter text, that space is regarded as matching
the space in the delimiter structure and removed; the expansion of the macro
is therefore the tokens remaining once the leading space has been removed,
preceded by a protected space |{ }|.
\EndComment

%%% Adjunct macros -- <space>... -> {<space>}...

\def \m at kespacexplicit #1\@nd
    {\futurelet \h at ad \m at kesp@cexplicit #1\@nd}

\def \m at kesp@cexplicit #1\@nd
    {\ifx \h at ad \sp at cetoken
          \@x \def \@x \b at dy
                     \@x {\pr at tectspace #1\@nd}%
     \else
          \def \b at dy {#1}%
     \fi
    }%

\@x \def \@x \pr at tectspace \sp at ce #1\@nd {{ }#1}

\Comment
The final step is to re-instate the category code of commercial-at.
\EndComment

%%% re-instate category code of commercial-at

\catcode `\@ = \the \@code

\Comment
Thus letter-spacing is accomplished.  The author hopes both that the code will
be found useful and that the explanation which accompanies it will be found
informative and interesting.
\EndComment
-------------- next part --------------


\newdimen \naturalwidth
\newdimen \naturaldepth
\newdimen \naturalheight

\chardef \atcode = \the \catcode `\@
\catcode `\@ = 11

\newbox \l at tterspacebox
\newtoks \l at tterspacetoks

\let \@x = \expandafter

\def \letterspace #1#%
    {\def \hb at xmodifier {#1}%
     \afterassignment \l at tterspace
     \l at tterspacetoks =
    }

\def \l at tterspace 
    {\setbox \l at tterspacebox = \hbox {\the \l at tterspacetoks}%
     \naturalwidth =  \wd \l at tterspacebox
     \naturaldepth =  \dp \l at tterspacebox
     \naturalheight = \ht \l at tterspacebox
     \hbox \hb at xmodifier 
        {\@x \l at tt@rspace \@x {\@x }\the \l at tterspacetoks \@nd}%
    }

\def \l at tt@rspace #1#2\@nd
    {\def \1{#1}%
     \def \2{#2}%
     \1%
     \ifx \1\empty \else \ifx \2\empty \else \hss \fi \fi
     \ifx \2\empty
          \let \n at xt = \relax
     \else
          \futurelet \2\m at kespaceexplicit #2\@nd
          \ifx \1\space \hss \fi
          \def \n at xt {\expandafter \l at tt@rspace \2\@nd}%
     \fi
     \n at xt
    }

\def \m at kespaceexplicit #1#2\@nd {\if \2 \def \2{{ }#1#2}\else \def \2{#1#2}\fi}

\catcode `\@ = \the \atcode

%%% Examples

%%% \letterspace {Now is the time for all good men}
%%% \letterspace to \hsize {Now is the time for all good men}
%%% \letterspace spread 0.3 \hsize {Now is the time for all good men}
%%% \letterspace to 1.5 \naturalwidth {Now is the time for all good men}
%%% \letterspace spread 0.5 \naturalwidth {Now is the time for all good men}

%%% \end
-------------- next part --------------
\let\lqq=^^fe \let\rqq=^^ff \def\pomlka{---}

\newdimen\proklad \proklad=2pt \newdimen\mm
\def\prostrkej#1{\bgroup\let\pp=\relax\let\next=\strk \strk#1^^X}
\def\strk{\afterassignment\osetriznak \let\znak= }
\def\osetriznak{%
  \if \noexpand\znak^^X\let\next=\konec
  \else \if\noexpand\znak\space \space\kern\proklad\let\pp=\relax
        \else \ifcat \noexpand\znak A\prokladznaku
              \else \ifcat \noexpand\znak .\prokladznaku
                    \else \znak % makra, hranice skupin apod.
  \fi \fi \fi \fi \next}
\def\prokladznaku{\setbox0=\hbox{\pp\znak}%
    \setbox1=\hbox{\pp}\setbox2=\hbox{\znak}%
    \mm=\wd0 \advance\mm-\wd1 \advance\mm-\wd2
    \advance\mm\proklad
    \ifhmode \kern\mm \fi \znak
    \global\let\pp=\znak }
\def\konec{\kern\proklad \egroup}


More information about the csTeX mailing list