diff options
author | Karl Berry <karl@freefriends.org> | 2009-09-20 23:29:41 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-09-20 23:29:41 +0000 |
commit | 2c20e449c234f30eb26e3cbbd9cd48b281842a37 (patch) | |
tree | 60bd80b52ddd7f2e6250c5ab90e047ad455fa475 /Master/texmf-dist/doc/latex/perltex | |
parent | b209fd55656d0a2b7714c317d2a6656af4b1505e (diff) |
perltex 1.9 (20sep09)
git-svn-id: svn://tug.org/texlive/trunk@15387 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex/perltex')
-rw-r--r-- | Master/texmf-dist/doc/latex/perltex/example.tex | 88 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/perltex/perltex.pdf | bin | 323424 -> 333020 bytes |
2 files changed, 88 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/perltex/example.tex b/Master/texmf-dist/doc/latex/perltex/example.tex new file mode 100644 index 00000000000..95de2dc062c --- /dev/null +++ b/Master/texmf-dist/doc/latex/perltex/example.tex @@ -0,0 +1,88 @@ +%% +%% This is file `example.tex', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% perltex.dtx (with options: `example') +%% +%% This is a generated file. +%% +%% Copyright (C) 2009 Scott Pakin <scott+pt@pakin.org> +%% +%% This file may be distributed and/or modified under the conditions of +%% the LaTeX Project Public License, either version 1.3c of this license +%% or (at your option) any later version. The latest version of this +%% license is in: +%% +%% http://www.latex-project.org/lppl.txt +%% +%% and version 1.3c or later is part of all distributions of LaTeX version +%% 2006/05/20 or later. +%% +\documentclass{article} +\usepackage[optional]{perltex} +\usepackage{environ} +\usepackage{hyperref} + +\ifperl + + \perlnewcommand{\dolinkwords}[3]{ + # Preprocess our arguments. + $url = $_[0]; + $url =~ s/\\\%s/\%s/g; + %stopwords = map {lc $_ => 1} split " ", $_[1]; + $stopwords{""} = 1; + $text = $_[2]; + + # Replace LaTeX code in the text with placeholders. + $placeholder = "ABCxyz123"; + %substs = (); + $replace = sub {$substs{$placeholder} = $_[0]; $placeholder++}; + $text =~ s/\\(begin|end)\s+\{[a-z]+\}/$replace->($&)/gse; + $text =~ s/\\[a-z]+/$replace->($&)/gse; + + # Hyperlink each word that's not in the stop list. + $newtext = ""; + foreach $word (split /((?<=[-\A\s])[\'a-z]+\b)/i, $text) { + $lcword = lc $word; + if (defined $stopwords{$lcword} || $lcword =~ /[^a-z]/) { + $newtext .= $word; + } + else { + $newtext .= sprintf "\\href{$url}{%s}", $lcword, $word; + } + } + + # Restore original text from placeholders and return the new text. + while (($tag, $orig) = each %substs) { + $newtext =~ s/\Q$tag\E/$orig/gs; + } + return $newtext; + } + + \NewEnviron{linkwords}[2][]{\dolinkwords{#2}{#1}{\BODY}}{} + +\else + + \newenvironment{linkwords}[2][]{}{} + +\fi + +\begin{document} + +\newcommand{\stopwords}{a an the of in am and or but i we me you us them} + +\begin{linkwords}[\stopwords]{http://www.google.com/search?q=define:\%s} +\begin{verse} + I'm very good at integral and differential calculus; \\ + I know the scientific names of beings animalculous: \\ + In short, in matters vegetable, animal, and mineral, \\ + I am the very model of a modern Major-General. +\end{verse} +\end{linkwords} + +\end{document} +\endinput +%% +%% End of file `example.tex'. diff --git a/Master/texmf-dist/doc/latex/perltex/perltex.pdf b/Master/texmf-dist/doc/latex/perltex/perltex.pdf Binary files differindex c1cb69cc6ad..1af4c31e085 100644 --- a/Master/texmf-dist/doc/latex/perltex/perltex.pdf +++ b/Master/texmf-dist/doc/latex/perltex/perltex.pdf |