From bcdf6c829c6761de02484473ebe43fa3760adcaa Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Wed, 12 May 2021 03:01:15 +0000 Subject: CTAN sync 202105120301 --- support/TeX4ht/source/tex4ht-xhtmml-xtpipes.tex | 751 ++++++++++++++++++++++++ 1 file changed, 751 insertions(+) create mode 100644 support/TeX4ht/source/tex4ht-xhtmml-xtpipes.tex (limited to 'support/TeX4ht/source/tex4ht-xhtmml-xtpipes.tex') diff --git a/support/TeX4ht/source/tex4ht-xhtmml-xtpipes.tex b/support/TeX4ht/source/tex4ht-xhtmml-xtpipes.tex new file mode 100644 index 0000000000..37461cd573 --- /dev/null +++ b/support/TeX4ht/source/tex4ht-xhtmml-xtpipes.tex @@ -0,0 +1,751 @@ +% $Id: tex4ht-xhtmml-xtpipes.tex 740 2020-06-13 22:35:32Z karl $ +% htlatex tex4ht-xhtmml-xtpipes "xhtml,next,3" "" "-d./" + +% Copyright 2009-2020 TeX Users Group +% Copyright 1996-2009 Eitan M. Gurari +% Released under LPPL 1.3c+. +% See tex4ht-cpright.tex for license text. + +\documentclass{article} + \Configure{ProTex}{log,<<<>>>,title,list,`,[[]]} + \usepackage{url} + \input{common.tex} +\begin{document} +\input tex4ht-cpright.tex +\input tex4ht-dir + +%%%%%%%%%%%%%%%%%% +\part{Post Processing for HTML Output Mode} +%%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%% +\section{Outline} +%%%%%%%%%%%%%%%%%% + +\AtEndDocument{\OutputCodE\} + +\Needs{"xmllint --valid --noout xhtmml.4xt"} + +\<<< + + + + + + `

+ `

  • + ` + ` + ` + ` + + +>>> + + +% +\AtEndDocument{\OutputCodE\} + +\ifdojava + \Needs{" + if [ ! -d \XTPIPES\space]; then exit 1; fi + ; + javac XhtmmlUtilities.java -d \XTPIPES + "} +\fi + +\<<< +package tex4ht; +/* XhtmmlUtilities.java (`version), generated from `jobname.tex + Copyright (C) 2009-2010 TeX Users Group + Copyright (C) `CopyYear.2008. Eitan M. Gurari +` */ + +import org.w3c.dom.*; +public class XhtmmlUtilities { + ` + ` + ` + ` + ` + ` + ` +} +>>> + + + + + +\<<< + +>>> + + + + +\<<< +public static void mrow(Node dom) { + barsIntoFenced( dom ); + digitsIntoNumbers( dom ); +} +>>> + + +\<<< + +>>> + + + + +\<<< +public static void math(Node dom) { + barsIntoFenced( dom ); + digitsIntoNumbers( dom ); +} +>>> + + + + + + + + + + + + +%%%%%%%%%%%%% +\section{Empty Paragraphs} +%%%%%%%%%%%%% + +\

    <<< + +>>> + +\

    <<< + +>>> + + +\<<< +public static void p(Node dom) { + Node pNode = dom.getFirstChild(); + if( pNode.hasChildNodes() ){ + boolean drop = true; + Node child = pNode.getFirstChild(); + while( child != null ){ + short type = child.getNodeType(); + if( + (type == Node.ELEMENT_NODE) + || + (type == Node.CDATA_SECTION_NODE) + || + (type == Node.TEXT_NODE) + && + !((Text) child).getWholeText().trim().equals("") + ){ + drop = false; break; + } + child = child.getNextSibling(); + } + if( drop ){ + dom.removeChild( pNode ); + } + } else { + dom.removeChild( pNode ); + } +} +>>> + + + +%%%%%%%%%%%%% +\section{Tables} +%%%%%%%%%%%%% + + +Remove Empty Trailling Row + +\

    <<< + +>>> + + +\<<< +public static void table(Node dom) { + Node tableNode = dom.getFirstChild(); + if( tableNode.hasChildNodes() ){ + Node trChild = tableNode.getLastChild(); + while( (trChild != null) + && + !trChild.getNodeName().equals("tr") ){ + trChild = trChild.getPreviousSibling(); + } + if( (trChild != null) && trChild.hasChildNodes() ){ + Node tdChild = trChild.getLastChild(); + while( (tdChild != null) + && + !tdChild.getNodeName().equals("td") ){ + tdChild = tdChild.getPreviousSibling(); + } + if( !tdChild.hasChildNodes() ){ + tableNode.removeChild( trChild ); + } else { + Node child = tdChild.getFirstChild(); + if( + (child.getNodeType() == Node.TEXT_NODE) + && + ((Text) child).getWholeText().trim().equals("") + && + (child.getNextSibling() == null) + ){ + tableNode.removeChild( trChild ); +} } } } } +>>> + + + + + + + + +%%%%%%%%%%%%% +\section{List Items} +%%%%%%%%%%%%% + + +%%%%%%%%%%%%% +\subsection{Outline} +%%%%%%%%%%%%% + + + +\
  • <<< + +>>> + + + + +\<<< +public static void li(Node dom) { + Node liNode = dom.getFirstChild(); + Node liChild; + boolean hasBlock = false, hasInline = false; + ` + if( hasBlock && hasInline ){ + `

    + ` + } +} +>>> + + + + +%%%%%%%%%%%%% +\subsection{Place Inline Code into Paragraphs} +%%%%%%%%%%%%% + + + +\

    <<< +liChild = liNode.getLastChild(); +Element g = ((Document) dom).createElement("p"); +g.setAttribute("class", "noindent"); +while( liChild != null ){ + short type = liChild.getNodeType(); + if( ` ){ + ` + liChild = liChild.getPreviousSibling(); + } else { + Node nextChild = liChild; + liChild = liChild.getPreviousSibling(); + ` +} } +>>> + + +\<<< +nextChild = liNode.removeChild(nextChild); +type = nextChild.getNodeType(); +if( + (type != Node.COMMENT_NODE) + && + ( + (type != Node.TEXT_NODE) + || + !((Text) nextChild).getWholeText().trim().equals("") + ) +){ + if( g.hasChildNodes() ){ + g.insertBefore( nextChild, g.getFirstChild() ); + } else { + g.appendChild( nextChild ); +} } +>>> + +%%%%%%%%%%%%% +\subsection{Place Paragraphs into List Items} +%%%%%%%%%%%%% + +\<<< +if( liNode.hasChildNodes() ){ + liNode.insertBefore( g, liNode.getFirstChild() ); +} else { + liNode.appendChild( g ); +} +>>> + + +\<<< +if( g.hasChildNodes() ){ + Node nextChild = liChild.getNextSibling(); + if( nextChild == null ){ + liNode.appendChild( g ); + } else { + liNode.insertBefore( g, nextChild ); + } + g = ((Document) dom).createElement("p"); + g.setAttribute("class", "noindent"); +} +>>> + + + +%%%%%%%%%%%%% +\subsection{Check Nature of Item Content} +%%%%%%%%%%%%% + +\<<< +liChild = liNode.getFirstChild(); +while( liChild != null ){ + short type = liChild.getNodeType(); + if( ` ){ hasBlock = true; } + else if( type == Node.TEXT_NODE ){ + if( !((Text) liChild).getWholeText().trim().equals("") ){ + hasInline = true; + } } + else if( + (type != Node.COMMENT_NODE) + && + (type != Node.PROCESSING_INSTRUCTION_NODE ) + ){ + hasInline = true; + } + liChild = liChild.getNextSibling(); +} +>>> + + +\<<< +(type == Node.ELEMENT_NODE) +&& +( + liChild.getNodeName().equals("p") + || + liChild.getNodeName().equals("ol") + || + liChild.getNodeName().equals("ul") + || + liChild.getNodeName().equals("div") + || + liChild.getNodeName().equals("table") +) +>>> + + + +%%%%%%%%%%%%%%%%%% +\section{Scripted Math |...|} +%%%%%%%%%%%%%%%%%% + + + + + +\<<< +static void barsIntoFenced(Node dom) { + Node rightBarNode = null; + Node mrowNode = dom.getFirstChild(); + Node mrowChild = mrowNode.getLastChild(); + while( mrowChild != null ){ + if( + mrowChild.getNodeName().equals("msub") + || + mrowChild.getNodeName().equals("msup") + || + mrowChild.getNodeName().equals("msubsup") + ){ + Node firstChild = mrowChild.getFirstChild(); + if( + (firstChild.getChildNodes().getLength() == 1) + && + firstChild.getTextContent().equals( "|" ) + ){ + rightBarNode = mrowChild; + } } + else + if( + (rightBarNode != null) + && + mrowChild.getNodeName().equals("mo") + && + (mrowChild.getChildNodes().getLength() == 1) + && + mrowChild.getTextContent().equals( "|" ) + ){ + if(mrowChild.getNextSibling() != rightBarNode){ + ` + } + rightBarNode = null; + } + mrowChild = mrowChild.getPreviousSibling(); +} } +>>> + + + + + + +\begin{verbatim} + A + |B|^2 + C + + A + + + | # + B # + # + # + | # + # + # + 2 # + # + # + + + C + +\end{verbatim} + + +\<<< +rightBarNode.removeChild( rightBarNode.getFirstChild() ); +Node sub = rightBarNode.getFirstChild(); +Node mfenced = ((Document) dom).createElement( "mfenced" ); +rightBarNode.insertBefore( mfenced, sub ); +((Element) mfenced).setAttribute("open","|"); +((Element) mfenced).setAttribute("close","|"); +((Element) mfenced).setAttribute("separator",""); +Node node = mrowChild.getNextSibling(); +while( node != rightBarNode ){ + Node next = node.getNextSibling(); + mrowNode.removeChild( node ); + mfenced.appendChild( node ); + node = next; +} +mrowNode.removeChild( mrowChild ); +mrowChild = mrowNode.getLastChild(); +>>> + + +%%%%%%%%%%%%%%%%%% +\section{Digits into Numbers} +%%%%%%%%%%%%%%%%%% + +\<<< +static void digitsIntoNumbers(Node dom){ + Node mrowNode = dom.getFirstChild(); + Node mrowChild = mrowNode.getFirstChild(); + short state = `; + Node fromNode = null, + toNode = null; + while( mrowChild != null ){ + switch( state ){ + case `: + if( mrowChild.getNodeName().equals("mn") ){ + state = `; + fromNode = mrowChild; + toNode = mrowChild; + } + break; + case `: + boolean bool = true; + if( mrowChild.getNodeName().equals("mn") ){ + toNode = mrowChild; + bool = ( mrowChild.getNextSibling() == null ); + } + else + { ` } + if( bool ) + { ` + if( bool ){ + ` + node.replaceChild( ((Document) dom).createTextNode(num), + node.getFirstChild() + ); + } + state = `; + fromNode = null; + toNode = null; + } } + mrowChild = mrowChild.getNextSibling(); +} } +>>> + + +\<<< +0 +>>> + +\<<< +1 +>>> + +\<<< +Node next; +String num = ""; +Node node = fromNode; +while( node != toNode ){ + num += node.getTextContent(); + next = node.getNextSibling(); + mrowNode.removeChild( node ); + node = next; +} +num += node.getTextContent(); +>>> + +\<<< +for( Node node = fromNode; ; node = node.getNextSibling()){ + String str = node.getTextContent(); + if( str.length() > 1 ){ bool = false; break; } + if( !str.replaceAll("[0-9]","").equals("") ){ bool = false; break; } + if( node == toNode ){ break; } +} +>>> + + + +\<<< +String s = null; +Node base; +if( + ( mrowChild.getNodeName().equals("msub") + || + mrowChild.getNodeName().equals("msup") + || + mrowChild.getNodeName().equals("msubsup") + ) + && + ((s = (base = mrowChild.getFirstChild()) + . getTextContent()).length() == 1 ) + && + s.replaceAll("[0-9]","").equals("") +){ + ` + ` + mrowNode.removeChild( node ); + num += s; + Node mn = ((Document) dom).createElement("mn"); + mn.appendChild( ((Document) dom).createTextNode(num) ); + mrowChild.replaceChild( mn, base); + + bool = false; + state = `; + fromNode = null; + toNode = null; +} +>>> + + + +%%%%%%%%%%%%%%%%%% +\section{mstyle} +%%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%% +\subsection{Mstyle as Parent of an Element} +%%%%%%%%%%%%% + +Merge mstyle into its child. For instance + +\begin{verbatim} + + F + +\end{verbatim} + +into + +\begin{verbatim} +F +\end{verbatim} + +\<<< + +>>> + +\<<< + + + + + + + + + +>>> + +%%%%%%%%%%%%% +\subsection{Mstyle as Parent of Text} +%%%%%%%%%%%%% + + +\begin{verbatim} + + div + +\end{verbatim} + +into + +\begin{verbatim} +div +\end{verbatim} + +\<<< + + ` + ` + ` + + +>>> + + +\<<< + + + + + + + +>>> + + +%%%%%%%%%%%%%%%%%% +\section{Shared} +%%%%%%%%%%%%%%%%%% + + + +\<<< + + +>>> + +\<<< + + + + + + +]]> +>>> + + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% END END END END END END END END END END END END END END END END +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\ifdojava +\AtEndDocument{\Needs{% + "pushd \XTPIPES || exit 1 + ; + jar cf tex4ht.jar * + ; + popd + ; + if [ ! -d \TEXMFTEXivBIN\space]; then exit 1; fi + ; + mv \XTPIPES tex4ht.jar \TEXMFTEXivBIN + ; + if [ ! -d \TEXMFTEXivXTPIPES\space]; then exit 1; fi + ; + cp \XTPIPES xtpipes/lib/* + \TEXMFTEXivXTPIPES + ; +"}} +\fi + +%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\end{document} +%%%%%%%%%%%%%%%%%%%%%%%%%%%% + -- cgit v1.2.3