# command \\ within HCode

how can I use the command \\ within HCode? Within a javascript part which I embed with HCode, I need to use "\\alpha", however my htlatex always returns strange errors. Best Christian Example

\documentclass[12pt,a4paper,notitlepage,german,twoside]{book}
\begin{document}
\HCode{<div id="box"  class="jxgbox" style="width: 650px; height: 530px;"></div>
<script>// \Hnewline
board = JXG.JSXGraph.initBoard('box', {boundingbox: [-5, 5, 5, -5]});
board.create('text',[-1,function(){return pal.Y()/2},"$\\alpha$"],{strokeColor:'black'}); }
</script>
\end{document}


und aus dem cfg file

\Preamble{xhtml,mathml}
\begin{document}
\EndPreamble

• could you please provide a minimal working example of your code? especially the JavaScript configuration. – michal.h21 Sep 20 '17 at 15:48
• sorry, since I need to use some html commands within the HCode, the code is not correctly displayed here. I hope, the most important line, that one with the JSXGraph command helps. – ChristianB Sep 21 '17 at 8:13

You need to escape the \ character, for example using \string command. First of all, I would move the code for board insertion out of the TeX file, because you wouldn't be able to compile it to PDF without error. I would create package jsxgraph.sty, which will contain some dummy command for the PDF mode:

\ProvidesPackage{jsxgraph}
\newcommand\jsxgraph{}

\endinput


The TeX file can be simplified to the following form:

\documentclass[12pt,a4paper,notitlepage,german,twoside]{book}
\usepackage{jsxgraph}
\begin{document}
\jsxgraph
\end{document}


The real work will be done in the configuration file for tex4ht, jsxgraph.4ht:

\renewcommand\jsxgraph{\a:jsxgraph}
\NewConfigure{jsxgraph}{1}
\Configure{jsxgraph}{\ifvmode\IgnorePar\fi\EndP\HCode{<div id="box"  class="jxgbox" style="width: 650px; height: 530px;"></div>
<script type="text/javascript">// \Hnewline
board = JXG.JSXGraph.initBoard('box', {boundingbox: [-5, 5, 5, -5]});
board.create('text',[-1,function(){return pal.Y()/2},"$\string\\alpha$"],{strokeColor:'black'});
</script>}}


The new configuration jsxgraph is defined here, with one parameter. The command \jsxgraph is redefined then, to include the configuration (using \a:jsxgraph). We can then use \Configure{jsxgraph}{...}. I changed two things to your original code: the \ifvmode\IgnorePar\fi\EndP will prevent paragraph tags to be inserted around the graph, because it would result in invalid HTML code, and \string\\alpha will insert \\alpha string correctly.

This is the resulting HTML:

<link rel="stylesheet" type="text/css" href="sample.css" />
<script type="text/javascript">var a = "\\alpha";</script><script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/MathJax/MathJax.js"></script></head><body
>
<div id="box" class="jxgbox" style="width: 650px; height: 530px;"></div> <script type="text/javascript">//
board = JXG.JSXGraph.initBoard('box', {boundingbox: [-5, 5, 5, -5]}); board.create('text',[-1,function(){return pal.Y()/2},"$\\alpha$"],{strokeColor:'black'}); </script>
</body></html>