Vyplnovani formulare -- ztrata mezer

Petr Olsak petr at olsak.net
Thu Mar 27 08:35:11 CET 2003


On Wed, 26 Mar 2003, Petr Mandys wrote:

> Zdravim!
>
> Myslenka je jasna: Budu si odebirat postupne znaky a centrovat je do
> \hboxu potrebne sirky, ktere pak budu skladat za sebe...
>
> V cem je teda problem: Jak zajistit, aby mi nemizely mezery? Odebirani po
> znaku delam pomoci makra
>
> \def\vytiskni#1{\expandafter\odebertoken#1;}
> \def\odebertoken#1#2;{\zpracuj{#1}\odebertoken#2;}
>
> (velmi zjednodusene napsano...) Jenze mezera se mi v takovem pripade
> sezere, jako nepovinna mezera pred parametry makra...

Je potreba pouzit \futurelet. Muzete se podivat do kodu nize, ve kterem
rozebiram taky jednotlive tokeny a davam pozor, abych neznicil mezeru.
Je to sice o necem jinem, ale princip je stejny.

Kod jsem poslal panu Hagenovi, kdyz potreboval ve vystupech \specialu
konvertovat vyskyty znaku ( na dvojici \(. Potreboval to
pravdepodobne nekam do ConTeXtu.

Zdravim

Petr Olsak

----------------------------------------

On Thu, 23 Jan 2003, Hans Hagen wrote:

> Hi Petr,
>
> How about output conversion:
>
> say that i want to write a ( to a PS file, then it needs to be escaped to
> \( ; does you rmechanism also work on that end (writes, specials)

I decided that the implementation of the conversion you asked is not
a simple task in encTeX. There exist a solution of this task on macro
level. May be, you are using a similar solution.

\def\convert #1{\def\cnvout{}\doconvert #1\convert}

% The macro \convert copies its parameter to the body of the macro
% \cnvout and does the conversion "(" -> "\(", ")" -> "\)".
% If the "{" or "}" occurs in the parameter then the ASCII code of this
% character is kept but catcode will be changed to 11.
% All another tokens (including control sequences) are copied
% without any changes.

\def\doconvert {\futurelet\next\testtoken}

\def\testtoken{\ifx\next\convert \let\next=\cnvfinal
  \else \ifx\spacetoken\next \let\next=\insertspace
  \else \ifx\bgroup\next \let\next=\insertbracein
  \else \ifx\egroup\next \let\next=\insertbraceout
  \else \ifx(\next \let\next=\insertescape
  \else \ifx)\next \let\next=\insertescape
  \else \let\next=\inserttoken
  \fi\fi\fi\fi\fi\fi \next}

\let\ex=\expandafter

\def\cnvfinal#1{}
\def\cnvnext{\afterassignment\doconvert \let\next= }
\def\addcnvout #1{\ex\def \ex\cnvout \ex{\cnvout#1}}
\def\inserttoken #1{\addcnvout #1\doconvert}
\def\insertescape #1{\ex\addcnvout\ex{\normalbackslash#1}\doconvert}
\def\insertbracein {\ex\addcnvout \normalbracein \cnvnext}
\def\insertbraceout {\ex\addcnvout \normalbraceout \cnvnext}
\def\insertspace {\addcnvout { }\cnvnext}

\bgroup
  \uccode`X=`\\ \uppercase{\gdef\normalbackslash{X}}
  \uccode`X=`\{ \uppercase{\gdef\normalbracein{X}}
  \uccode`X=`\} \uppercase{\gdef\normalbraceout{X}}
\egroup
\edef\next{\let\noexpand\spacetoken= \space}\next

% There is a sketch ot hte macros used for \shipout and \write
% with the use of the \convert macro.

\def\yourspecial #1{...
   \convert {#1}\special{text to dvi: "\cnvout", etc.}%
}
% No \toks are needed because the expansion is done immediatelly.

\def\yourwrite #1{...
   \convert {#1}\toks0=\expandafter{\cnvout}
   \edef\next{\write\fileout{text to write, "\the\toks0", etc.}}\next
}
% We partially expand the write argument because the full expansion is
% done late when the \cnvout can have a new value.
% The full expansion of \cnvout by \edef is not recommended because it
% may include the control sequences no-expanded and converted to the
% <byte_sequences> by encTeX.

Petr Olsak





More information about the csTeX mailing list