xhtmltools-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xhtmltools-devel] Changes to xhtmltools/xhtml2latex


From: Jaime E. Villate
Subject: [Xhtmltools-devel] Changes to xhtmltools/xhtml2latex
Date: Wed, 20 Feb 2002 16:26:41 -0500

Index: xhtmltools/xhtml2latex
diff -c xhtmltools/xhtml2latex:1.5 xhtmltools/xhtml2latex:1.6
*** xhtmltools/xhtml2latex:1.5  Wed Nov  7 17:53:45 2001
--- xhtmltools/xhtml2latex      Wed Feb 20 16:26:40 2002
***************
*** 1,11 ****
  #! /bin/sh
! # $Id: xhtml2latex,v 1.5 2001/11/07 22:53:45 villate Exp $
  #
  # xhtml2latex - creates a LaTeX file from an XHTML file
  #
! # Copyright (C) Jaime Villate <address@hidden>, 2001
  #
! # This program is free software; you can redistribute it and/or
  # modify it under the terms of the GNU General Public License
  # as published by the Free Software Foundation; either version 2
  # of the License, or (at your option) any later version.
--- 1,13 ----
  #! /bin/sh
! # $Id: xhtml2latex,v 1.6 2002/02/20 21:26:40 villate Exp $
  #
  # xhtml2latex - creates a LaTeX file from an XHTML file
  #
! # Copyright (C) 2001, 2002, Jaime Villate <address@hidden>
  #
! # This program is part of xhtmltools
! #
! # xhtmltools is free software; you can redistribute it and/or
  # modify it under the terms of the GNU General Public License
  # as published by the Free Software Foundation; either version 2
  # of the License, or (at your option) any later version.
***************
*** 20,90 ****
  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  
  
! # edit the following line with the directory where the default XSL pages are
! XSL=/usr/lib/sgml/stylesheet/xsl
! STYLESHEET='xhtml2latex.xsl'
  TMP=XHTML2LATEX-TEMP-$$
  
! case $1 in
      -s) STYLESHEET=$2
!         shift 2
        ;;
      -h|--help)
!         echo "Usage: `basename $0` [-s stylesheet] file.xhtml" >&2
!       exit 1
          ;;
! esac
  
! if [ $# -gt 2 ]
! then
!   echo "Usage: `basename $0` [-s stylesheet] file.xhtml" >&2
!   exit 1
! fi
  
! if [ $# -eq 1 ]
  then
!   XSLFILE=$STYLESHEET
!   if [ ! -r $STYLESHEET ]
    then
!     XSLFILE=$XSL/$STYLESHEET
!     if [ ! -r $XSLFILE ]
      then
!       echo Cannot read \"$STYLESHEET\".  Exiting. >&2
!       exit 1
!     fi
!   fi
!   if [ ! -r $1 ]
!   then
!     echo Cannot read \"$1\".  Exiting. >&2
!     exit 1
    fi
  
!   perl -pe '$f=1 if (/<body/);
  $f=0 if (/<\/body>/);
  $f=0 if (/<pre>/);
  $f=1 if (/<\/pre>/);
  if ($f==1) {
      s/\\/\\ensuremath{\\backslash}/g;
      s/&amp;/\\&amp;/g;
      s/_/\\_/g;
      s/\$/\\\$/g;
      s/\^/\\^{}/g;
      s/~/\\~{}/g;
-     s/#/\\#/g;
-     s/%/\\%/g;
      s/&gt;/\\ensuremath{&gt;}/g;
      s/&lt;/\\ensuremath{&lt;}/g;
      while (/(href=\"[^\"]*)\\/)
      {
        s/(href=\"[^\"]*)\\/$1/g;
      }
! }' $1 > $TMP
! 
!   (sabcmd $XSLFILE $TMP | sed "s/\\href{\#/\\hyperlink{/") || (rm -f $TMP; 
exit 1)
!   rm -f $TMP
!   exit 0
! else
!   echo "Usage: `basename $0` [-s stylesheet] file.xhtml" >&2
!   exit 1
! fi
  
--- 22,118 ----
  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  
  
! XSLTLATEX='/usr/share/sgml/xhtmltools/xhtml2latex.xsl'
  TMP=XHTML2LATEX-TEMP-$$
+ PARSER='xsltproc -nonet $XSLT $XHTML'
+ CONFFILE=~/.xhtmltools-conf
+ 
+ usage() {
+   echo "Usage:" 1>&2
+   echo "  `basename $0` [-s stylesheet] [-c config] xhtmlfile" 1>&2
+   echo " " 1>&2
+   exit 1
+ }
+ 
+ [[ $# -lt 1 ]] && usage
  
! while [[ $# -gt 0 ]]
! do
!   case $1 in
      -s) STYLESHEET=$2
!         shift
        ;;
      -h|--help)
!         usage
          ;;
!     -c) CONFFILE=$2
!         shift
!       ;;
!     -*)
!         usage
!         ;;
!     *)
!       XHTMLFILE=$1
!   esac
!   shift
! done
  
! [[ -n $XHTMLFILE ]] || usage
! 
! [[ -r $CONFFILE ]] && source $CONFFILE
  
! XSLTDIR=$(dirname $XSLTLATEX)
! 
! if [[ -n $STYLESHEET ]]
  then
!   if [[ -r $STYLESHEET ]]
    then
!     XSLT=$STYLESHEET
!   elif [[ -r $XSLTDIR/$STYLESHEET ]]
      then
!       XSLT=$XSLTDIR/$STYLESHEET
!     else
!       XSLT=$STYLESHEET
    fi
+ else
+  XSLT=$XSLTLATEX
+ fi
  
! if [[ ! -r $XSLT ]]
! then
!   echo Cannot find stylesheet \"$XSLT\" >&2
!   exit 1
! fi
! if [[ ! -r $XHTMLFILE ]]
! then
!   echo Cannot read XHTML file \"$1\" >&2
!   exit 1
! fi
! 
! perl -pe '$f=1 if (/<body/);
  $f=0 if (/<\/body>/);
  $f=0 if (/<pre>/);
  $f=1 if (/<\/pre>/);
  if ($f==1) {
      s/\\/\\ensuremath{\\backslash}/g;
      s/&amp;/\\&amp;/g;
+     s/#/\\#/g;
+     s/%/\\%/g;
      s/_/\\_/g;
+     s/\{/\\{/g;
+     s/\}/\\}/g;
      s/\$/\\\$/g;
      s/\^/\\^{}/g;
      s/~/\\~{}/g;
      s/&gt;/\\ensuremath{&gt;}/g;
      s/&lt;/\\ensuremath{&lt;}/g;
      while (/(href=\"[^\"]*)\\/)
      {
        s/(href=\"[^\"]*)\\/$1/g;
      }
! }' $XHTMLFILE > $TMP
  
+ XHTML=$TMP
+ (eval $PARSER | sed "s/\\href{\#/\\hyperlink{/") || (rm -f $TMP; exit 1)
+ rm -f $TMP
+ exit 0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]