From c59dc96c8263aaa3f471400ef7cab8336e7f1c1c Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 12 Jul 2014 22:24:39 +0000 Subject: testhyphens (12jul14) git-svn-id: svn://tug.org/texlive/trunk@34581 c570f23f-e606-0410-a88d-b1316a301751 --- .../source/latex/testhyphens/testhyphens.dtx | 406 +++++++++++++++++++++ 1 file changed, 406 insertions(+) create mode 100644 Master/texmf-dist/source/latex/testhyphens/testhyphens.dtx (limited to 'Master/texmf-dist/source/latex/testhyphens') diff --git a/Master/texmf-dist/source/latex/testhyphens/testhyphens.dtx b/Master/texmf-dist/source/latex/testhyphens/testhyphens.dtx new file mode 100644 index 00000000000..956ae6348dd --- /dev/null +++ b/Master/texmf-dist/source/latex/testhyphens/testhyphens.dtx @@ -0,0 +1,406 @@ +% \iffalse meta comment +% !TEX encoding = UTF-8 Unicode +% !TEX TS-program = pdflatex + +%<*internal> +\begingroup +\input docstrip.tex +\keepsilent +\preamble +Copyright 2014 Claudio Beccari All rights reserved. + + This system is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +This file is distributed under the LPPL licence, version 1.3c +dated 2008-05-04 or later as it appears in +CTAN/macros/latex/base/lppl.tex. +See the end of the file. + +IMPORTANT NOTICE: + +You are allowed to distribute this file under the conditions that are +specified in the source file testhyphens.dtx. + +If you receive only some of these files from someone, complain! + +You are NOT ALLOWED to distribute this file alone. +You are NOT ALLOWED to take money for the distribution or use +of either this file or a changed version, except for a nominal +charge for copying, etc. +\endpreamble +\askforoverwritefalse +% +\generateFile{testhyphens.sty}{f}{\from{testhyphens.dtx}{package}} + +\def\tmpa{plain} +\ifx\tmpa\fmtname\endgroup\expandafter\bye\fi +\endgroup +% +% \fi +% +%% \CharacterTable +%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z +%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z +%% Digits \0\1\2\3\4\5\6\7\8\9 +%% Exclamation \! Double quote \" Hash (number) \# +%% Dollar \$ Percent \% Ampersand \& +%% Acute accent \' Left paren \( Right paren \) +%% Asterisk \* Plus \+ Comma \, +%% Minus \- Point \. Solidus \/ +%% Colon \: Semicolon \; Less than \< +%% Equals \= Greater than \> Question mark \? +%% Commercial at \@ Left bracket \[ Backslash \\ +%% Right bracket \] Circumflex \^ Underscore \_ +%% Grave accent \` Left brace \{ Vertical bar \| +%% Right brace \} Tilde \~} +% \iffalse +%^^A The following trick uses the same date for every file header. +%\NeedsTeXFormat{LaTeX2e} +%<*driver> +\ProvidesFile{testhyphens.dtx}[% +% +%\ProvidesPackage{testhyphens}[% +%<*driver,package> +2014/07/07 v.0.5 +%Prints list of hyphenated words] +% +%<*driver> +] +% +%<*driver> +\documentclass{ltxdoc} +\GetFileInfo{testhyphens.dtx} + \title{The \textsf{testhyphens} package\\ + \thanks{This file + has version number \fileversion, last + revised on \filedate.}} + \author{Claudio Beccari\thanks{claudio dot beccari at gmail dot com}} + \date{} + \providecommand\babel{\pack{babel}} + \newcommand\lbr{\char123\relax}\newcommand\rbr{\char125\relax} + \newenvironment{sintassi}{% + \begin{quote}\parskip0pt\hfuzz10pt\ttfamily\obeylines + }{% + \end{quote}\ignorespaces + } + \renewcommand*\meta[1]{{\normalfont\textlangle\textit{#1}\textrangle}} + \newcommand*\pack[1]{\textsf{#1}} + \newcommand*\prog[1]{\texttt{#1}} + \newcommand*\Arg[1]{{\normalfont\texttt{\{}\meta{#1}\texttt{\}}}} + \renewcommand*\oarg[1]{\texttt{[}\marg{#1}\texttt{]}} + \let\marg\Arg + \newcommand*\acro[1]{\expandafter\textsc\expandafter{\MakeLowercase{#1}}} + \usepackage{multicol} + \usepackage[utf8]{inputenc} +\usepackage[LGR,T1]{fontenc} +\usepackage{lmodern,textcomp} +\usepackage[greek,italian,english]{babel} +\usepackage{testhyphens} +\begin{document} + \maketitle + \DocInput{testhyphens.dtx} +\end{document} +% +% \fi +% +% \CheckSum{0} +% \begin{abstract} +% This small file implements some code that was already published on TUGboat, +% but it is adapted to \LaTeX\ and it is enriched with other commands. It helps +% those who create hyphenation patterns, as well normal \LaTeX\ users, to test +% the correctness of the hyphenations of words lists. It works also with +% \prog{xelatex}. +% \end{abstract} +% \section{Introduction} +% +% This small package introduces the declaration |\testhyphens| and the environment +% |checkhyphens|. The declaration, to be used within a group where the hyphenation +% parameters may be optionally set to any specific value, and process a list +% of one or more space delimited words typesetting the one per line with hyphens +% between every syllable. +% +% The language, its hyphenation rules that are to be checked, may be the +% default language before entering the group, or can be a language specified +% with |\selectlanguage| within the group before activating the declaration: +% this declaration could be set within a |\foreignlangeuage|\Arg{language} +% argument or within the body of an |otherlanguage| environment. +% +% The environment |checkhyphens| accepts an optional argument to set the +% hyphenation parameters, and a body consisting of a list +% of one or more words; again words are separated by spaces, and if the +% user just pastes a text copied from somewhere that included punctuation, +% the punctuation signs are ignored, but are not taken off from the text. +% +% The main code was published long ago by Victor Eijkout, in ``The bag of +% tricks'', \emph{TUGboat} 14.4 (1993), p. 424. He himself states that +% that code was created by Jonathan Kew; Victor Eijkout just added an empty +% |\discretionary{}{}{}|; the idea came to him from the code created by +% Oliver Schoett that is used for the hyphenation exception list of TUGboat. +% Credit for the code goes completely to the persons mentioned above; I just +% added some sugar to use that code in \LaTeX\ documents for the benefit of +% hyphenation pattern creators, and of regular users who want to know how a +% certain word or the words of a certain sentence would be hyphenated by +% \TeX\ and friends. +% +% Of course this package does not tell the whole truth: in fact \TeX\ and +% friends hyphenate words only when certain conditions are met; these +% conditions are stated in Appendix~H of the \TeX\-book, which is and remains +% the primary reference for understanding the hyphenation process used by +% \TeX\ and friends. + +% Sometimes the user complains that certain words are not hyphenated; the user +% might use this package and find out that her/his words are regularly +% hyphenated; then what's happening? Simply those conditions are not met. +% Therefore the full understanding of the above mentioned Appendix~H is +% fundamental before complaining about \TeX\ not working properly with +% hyphenations and possibly before raising a bug notice. +% +% \section{Usage} +% This package has been tested with |pdflatex| and |xelatex|; it should +% work also with |lualatex| but it was not tested with this engine. +% +% Remember that Normal Plain \TeX\ and \LaTeX\ have available the command +% |\showhyphens| but, differently from this package, that command works +% only when the typesetting engine is |tex| or |pdftex| and the result +% appears on the console window and in the \texttt{.log} file -- no written +% record remains available to the user; for |xelatex| there was a workaround +% provided by another package, but for some reasons it did not work in every +% circumstance. This package prints the result in the output document and +% works also with |xelatex|. +% +% This simple package is loaded simply with the usual statement +% \begin{flushleft} +%|\usepackage{testhyphens}| +% \end{flushleft} +% +% The package defines for the end user one declaration |\testhyphens| and +% one environment |checkhyphens| the syntax of which is the following: +%\begin{sintassi} +% |\begin{checkhyphens}|\oarg{hyphenation parameters} +% \marg{word list} +% |\end{checklist}| +%\end{sintassi} +% where \meta{hyphenation parameters} is a \emph{colon separated list} of two decimal +% digits that in order will be assigned by the environment respectively to +% |\lefthyphenmin| and |\righthyphenmin|, and \meta{word list} is self +% explanatory. Nevertheless it good to remember that the environment isolates +% single words by using a space as a word separator; this requires that the +% list is preceded and followed by spaces; setting the environment with the +% opening and closing statements on single lines, as shown above, is sufficient, +% while a source line such as +% |\begin{checkhyphens}|\oarg{hyphenation parameters}\marg{word list}|\end{checklist}| +% might not produce the desired result. +% +% \section{Using hyphenation parameters} +% The hyphenation parameters are just |\lefthyphenmin| and |\righthyphenmin|; +% they represent the minimum number of characters that the first and, respectively, +% the last word fragment must have before or until hyphenation takes place; in English +% the default values are 2 and~3; in Italian the default values are 2 and~2; in +% Greek the default values are 1 and~1. +% +% Let us make an example: the word \emph{idea} is spelt the same in English and +% Italian, although it is pronounced differently; but in both cases the word is +% not hyphenated at all in both languages. According to the Italian hyphenation +% rules its grammatical hyphenation is \emph{i-de-a}; in English possibly the +% grammatical hyphenation is the same; in any case the initial and the terminal +% syllables are too short to comply with the above mentioned \TeX\ hyphenation +% parameters, and \TeX\ refrains from hyphenating this word. In Greek, on the +% opposite, \foreignlanguage{greek}{ιδέα} it is divided into +% \foreignlanguage{greek}{ι-δέ-α}. +% +% If you use |checkhyphens| with the optional hyphenation parameters specified to +% 1 and~1 in Italian or in English, as in +%\begin{verbatim} +%checkhyphens[1:1]{idea} +%\end{verbatim} +% you don't get any useful result in English, and the word remains un-hyphenated; +% but in Italian is turns out to be \emph{i-de-a} as in Greek. +% +% This happens ecause the Italian patterns were created by hand and tested with +% parameters 1 and~1, even if for typesetting purposes the parameters are set +% to 2 and~2. In English the patterns were created by means of the program +% \prog{patgen} where parameters 2 and~3 were set. Typographically speaking +% the values 1 and~1 for italian are almost useless, but in certain difficult +% narrow-measure texts the user has the possibility to locally set the first and/or the +% second parameter to 1, and solve that particular instance of +% problematic narrow-measure typesetting. +% +% \section{Examples} +% Here we show some actual examples using either the declaration or the environment. +% While typesetting in English we might verify the hyphenation of some words. +% We set in the source file the following lines (notice the |\par| command is a reminder that the group containing the declaration must be used in vertical mode; a blank line would be equivalent): +%\begin{verbatim} +%\par +%{\testhyphens +%manifests instruments +%he analyses the samples and submits the analyses to the federal office +%} +%\end{verbatim} +% The result produced by this package is: +% +%{\testhyphens +%manifests instruments +%he analyses the samples and submits the analyses to the federal office +%} +% Notice the two instances of the word |analyses|; \TeX\ hyphenates them the +% same way in English, but one of the two is hyphenated in a wrong way; +% unfortunately there is no way for \TeX\ to distinguish homographic words +% that are not homophonic ones. In plain terms the verb ``analyses'' is stressed +% on the `y', while the noun ``analyses'' is stressed on the second `a'; +% the standard phonetic hyphenation rules for English probably should hyphenate +% the verb as ``an-a-lyses'', but \TeX\ works only on the spelling and not on +% the sound and does not make any logical analysis of the test to find out +% if a word plays the rôle of a noun or of a verb. In this and similar +% situations (for example: ``the record'' and ``to record'') the user should +% check a good reliable dictionary and possibly use an explicit discretionary +% hyphen~|\-|. +% +% While typesetting in Italian it is possible to insert in the source file +% a set of lines such as these: +%\begin{verbatim} +%\begin{checkhyphens} +%ebbe la bell'idea di viaggiare in scooter +%\end{checkhyphens} +%\end{verbatim} +% that produces the following result: +%\begin{otherlanguage*}{italian} +%\begin{checkhyphens} +%ebbe la bell'idea di viaggiare in scooter +%\end{checkhyphens} +%\end{otherlanguage*} +%Notice that ``idea'' cannot be hyphenated by \TeX\ when it is an isolated +% word; but in Italian the apostrophe is used (also) to mark a vocalic elision, +% therefore for hyphenation purposes, event it it not a letter, it is assigned +% a lowercase code, and it legally becomes part of a word, in our case the word +% ``bell'idea''. Therefore the patterns that involve the apostrophe produce +% the result shown above, where the first grammatical hyphen shows up again. +% \StopEventually{} +% +% While typesetting in Greek we might insert in the source file the following code: +%\begin{flushleft}\ttfamily\obeylines +%|\begin{checkhyphens}| +%\begin{otherlanguage*}{greek} +%επεξεργάζεται αρχεία τα οποἰα περιἐχουν τουσ χαρακτήρες που +% υπάρχουν στο πληκτρολὀγιο του υπολογιστἠ σας +%\end{otherlanguage*} +%|\end{checkhyphens}| +%\end{flushleft} +%and we would get: +%\begin{otherlanguage*}{greek} +%\begin{checkhyphens} +%επεξεργάζεται αρχεία τα οποἰα περιἐχουν τουσ χαρακτήρες που υπάρχουν +%στο πληκτρολὀγιο του υπολογιστἠ σας +%\end{checkhyphens} +%\end{otherlanguage*} +%while, had we set the hyphenation parameters different from the default +% values 1 and~1, as in: +%\begin{flushleft}\ttfamily\obeylines +%|\begin{checkhyphens}[2:2]| +%\begin{otherlanguage*}{greek} +%επεξεργάζεται αρχεία τα οποἰα περιἐχουν τουσ χαρακτήρες που +%υπάρχουν στο πληκτρολὀγιο του υπολογιστἠ σας +%\end{otherlanguage*} +%|\end{checkhyphens}| +%\end{flushleft} +%the result would be +%\begin{otherlanguage*}{greek} +%\begin{checkhyphens}[2:2] +%επεξεργάζεται αρχεία τα οποἰα περιἐχουν τουσ χαρακτήρες που υπάρχουν +%στο πληκτρολὀγιο του υπολογιστἠ σας +%\end{checkhyphens} +%\end{otherlanguage*} +% +% Notice that as things are at the moment of writing this documentations, +% the monotonic Greek hyphenation Patterns fail to hyphenate after an +% accented vowel followed by a consonant; the grammar allows to hyphenate +% in that position; but it correctly recognises the hiathus between an +% unaccented vowel and an accented one; at the same time the first Greek +% example shows very clearly the effect of |\lefthyphenmin=1| compared +% to the second example where |\lafthyphenmin=2|. On the other hand, missing +% some hyphen points is certainly a feature that precludes full hyphenation, +% but it does not produce hyphenation errors. +% +% \section{The code} +%\iffalse +%<*package> +%\fi +% The following code has very few modifications compared to the original code +% published by Victor Eijkout. For my own benefit I changed the declaration +% name from |\printhyphens| to |\t@sthyphens|; with an at-sign internal name +% it is less likely that the declaration is redefined by a user. I also moved +% the commend |\offinterlineskip| from its penultimate position in the original +% code to the first command to be executed within the |\vbox|; in this way +% I avoided certain cases in which the lack of interline skip would remain +% active after the environment closure. +% +% The code is based on treating the interword space as an active character +% that plays different rôles according to its position; it lets the +% declaration isolate the words to ne hyphenated and open suitable boxes, +% that are closed at the moment of processing the following word; the +% |\everypar| token list distinguishes the various actions to be performed +% at each step. +% +% But the trick is to set each word within a vertical box where the measure +% (the text width |\hsize| is zero; in this way each word is hyphenated at +% the first hyphen point, but the word fragment that remains ins the following +% line is still too long and gets hyphenated again; the process is repeated +% again and again until the initial string is exhausted. The contents of the +% |\vbox|, that now contains the syllables one per line, is reassembled to +% form une line, and this line is output within an |\hbox| and is therefore +% the box typeset in vertical mode; this is why the declaration must be issued +% in vertical mode, so as to strat processing the word list with the right +% foot; this is also why the word list must start and end with spaces; the +% first one before the first word opens the first box, and the last space after +% the last word closes and outputs the last box. +% \begin{macrocode} +\def\t@sthyphens{\everypar{\setbox0\lastbox \setbox1\hbox{\strut}\vbox\bgroup +\offinterlineskip +\everypar{\setbox0\lastbox \nobreak\hskip\z@}\dimen0=\hsize +\hsize=\z@ \hfuzz\maxdimen \def\par{\endgraf \hsize=\dimen0\getlastline +\egroup\endgraf}}\breakafterword} + +\def\breakafterword{\catcode`\^^M\active\catcode`\ \active} + +{\breakafterword\gdef^^M{\par}\global\let ^^M} + +\def\getlastline{\setbox0\lastbox\ifvoid0\let\next\nomorelines +\else\unskip\unpenalty\setbox1\hbox{\unhbox0\strut\discretionary{}{}{}% +\unhbox1}\let\next\getlastline\fi\next} + +\def\nomorelines{\unhbox1} +% \end{macrocode} +% The above code is substancially the original one; now we define the user +% declaration control sequence |\testhyphens| by letting it to assume the +% meaning of the internal control sequence. The we define the |checkhyphens| +% environment where we make sure that the whole process of the word list +% contained in its body takes place in vertical mode. In oder to process +% the optional argument for setting the hyphenation parameters, we define +% a delimited argument macro |\s@thyphenpars| that uses the \emph{colon} as +% argument delimiter. +% \begin{macrocode} +\let\testhyphens\t@sthyphens + +\newenvironment{checkhyphens}[1][\lefthyphenmin:\righthyphenmin]{% +\@tempcnta=\lefthyphenmin +\@tempcntb=\righthyphenmin +\s@thyphenpars[#1]\par\bgroup\t@sthyphens +}{% +\egroup\par +} + +\def\s@thyphenpars[#1:#2]{% +\@tempcnta=#1\relax +\@tempcntb=#2\relax +\unless\ifnum\@tempcnta=\lefthyphenmin \lefthyphenmin=\@tempcnta\fi +\unless\ifnum\@tempcntb=\righthyphenmin \righthyphenmin=\@tempcntb\fi +} +% \end{macrocode} +%\iffalse +% +%\fi +% That's all. Happy \TeX\-ing. +%\Finale +\endinput + -- cgit v1.2.3