Re: Changing text "in place"

Subject: Re: Changing text "in place"
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 4 May 1999 10:29:29 +0100 (BST)
Michel,

> I have a problem
> to get some characters that are "special" for LaTeX into a form that is
> acceptable (e.g., $, %, #, &, etc. have a special meaning). So the easiest
> would be to escape such characters when they get transferred

Actually for machine generated latex there is not really a lot of point
in leaving those with special meanings. I would just make all of those
normal letters in latex (ie \catcode`\$=12 etc) and not bother messing
around quoting stuff. Similarly

>  to the result tree, _if necessary_. The latter is important, since
> inside verbatim-like environments the characters can be used as-is, 

There is certainly no need to use verbatim environments for machine
generated latex. They are a minor aid to authoring but complicate
latex greatly and in this situation you just need to switch to
a monospaced font, you don't need to change all of latex's parsing
rules.

However...

> Before I go off and write a set
> of Java routines using xt's extension mechanism, 

You can do string replacements just in XSLT without relying on
extension.

eg
to change $ to \$ and % to \% and # to \#


<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";
  result-ns="">


<xsl:import href="http://andover.nag.co.uk/~davidc/verb.xsl"/>

<xsl:template match="/">
  <xsl:call-template name="string-replace">
    <xsl:param name="to" expr="'\$'"/>
    <xsl:param name="from" expr="'$'"/> 
    <xsl:param name="string">
      <xsl:call-template name="string-replace">
        <xsl:param name="to" expr="'\%'"/>
        <xsl:param name="from" expr="'%'"/> 
        <xsl:param name="string">
          <xsl:call-template name="string-replace">
            <xsl:param name="to" expr="'\#'"/>
            <xsl:param name="from" expr="'#'"/> 
            <xsl:param name="string" expr="."/>
          </xsl:call-template>
        </xsl:param>
      </xsl:call-template>
    </xsl:param>
  </xsl:call-template>
</xsl:template>

</xsl:stylesheet>


would convert 


<para>
hello world (%) (#) ($)
</para>


to 

hello world (\%) (\#) (\$)


David


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread