[OS X TeX] Re: help with \newcommand

Ramón Figueroa-Centeno ramonf at hawaii.edu
Tue Jun 8 20:10:40 CEST 2010


Aloha,

Will Robertson provided me with this code (in 20 minutes, unbelievable):

\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\makeatletter
\tex_outer:D \cs_new:Npn \encdef #1 {
  \begingroup
  \@sanitize
  \char_make_space:n {32}
  \afterassignment\endgroup
  \aftergroup \process_test_string:N
  \aftergroup #1
  \tl_gset:Nx #1
}
\cs_generate_variant:Nn \tl_replace_all_in:Nnn {Nxx}
\char_make_other:N \%
\char_make_comment:N \^^A
\cs_new:Npn \process_test_string:N #1 {
  \tl_replace_all_in:Nxx #1 {%} {%25}
  \tl_replace_all_in:Nxx #1 {~} {%20}
  \tl_replace_all_in:Nxx #1 {\@backslashchar} {%5C}
  \tl_replace_all_in:Nxx #1 {ó} {%97}
}
\char_make_comment:N \%
\makeatother
\ExplSyntaxOff
\begin{document}
\encdef\teststring{test string with \slash %percent and accents: ó}
\texttt\teststring
\end{document}

Awesome,

Ramón
-- 
View this message in context: http://macosx-tex.576846.n2.nabble.com/help-with-newcommand-tp5142889p5154867.html
Sent from the MacOSX-TeX mailing list archive at Nabble.com.



More information about the macostex-archives mailing list