2

I m new to tex and using tex4ht conversion with a ".cfg" file. In that I need to configure more than 600 elements. Hence I need to add for all the 600 elements in cfg.

Example:

sample.tex:

\documentclass{article}
\usepackage[english,czech]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{epub}
\begin{document}
\HalfTitle{Machine Learners}
\Title{Title}
\end{document}

epub.sty

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{epub}%
\usepackage{amsmath,amssymb}
\usepackage{endnotes}
\usepackage{epsfig}
\usepackage{graphicx}
\usepackage{latexsym}
\usepackage{multicol}
\usepackage{framed}%
\usepackage{glossaries}%
\usepackage[tex4ht]{hyperref}%
\def\toprule{\hline}%
\def\botrule{\hline}%
\def\midrule{\hline}%
\usepackage{listings}%
\usepackage{pgffor}% for the \foreach command
\newcommand{\HalfTitle}[1]{%
\Large#1%
}%

\newcommand{\Title}[1]{\Large#1}%

\endinput

epub.cfg

\Preamble{xhtml,fn-in,epub}
\RequirePackage{pgffor}% for the \foreach command

\renewcommand\ConfigurePar[1]{
  \foreach \para/\cls in {#1}{
    \Configure{\para}{\HCode{<p class="\cls">}}{\HCode{</p>\Hnewline}}%
    }
}

\begin{document}
\ConfigurePar{
  HalfTitle/TPHT,
  booktitle/TPT,
}
\EndPreamble

epub.4ht

\newcommand\ConfigurePar[1]{
 \foreach \paa/\cls in {#1}{
    \NewConfigure{\paa}{2}
    \let\tmp:\paa\\paa
    \renewcommand\\paa[1]{\a:\paa\tmp:\paa#1\b:\paa} 
    \Configure{\paa}{\HCode{<p class="\cls">}}{\HCode{</p>\Hnewline}}%
   }
}

and I am using the following command for conversion

htlatex sample "epub,xhtml" " -cunihft" "-cvalidate -p"

Is that possible to minimize the config code by passing ("halftitle", "TPHT") and ("booktitle", "TPT") as arguments in any external file and in use the argument values in CFG file. Like:

\Configure{ARG1}{\IgnorePar \EndP\HCode{<p class="ARG2">}}{\HCode{</p>\Hnewline}}%

Request your suggestions.

Thanks in advance Christober

3

EDIT

I would do this differently. Rather than using \Configure I would simply redefine the commands in the cfg file. Previously, I was using the \foreach command from pgffor but instead it seems better to use \forcsvlist from the etoolbox package. Then you can do what (I think) you want using

\newcommand\ConfigurePar[1]{\realConfigurePar#1!}
\def\realConfigurePar#1/#2!{% extract #1 up to / and then #2 up to !
    \csdef{#1}##1{\HCode{<p class="#2">}##1\HCode{</p>\Hnewline}}%
}

\forcsvlist\ConfigurePar{
  HalfTitle/TPHT,
  Title/TPT
}

So, \forcsvlist passes each element of the comma separated list to \ConfigurePar. In order to separate out the command name and the class name, \ConfigurePar gives everything to \realConfigurePar, which then redefines the corresponding LaTeX command so that it produces the required html.

In full gory detail: using the cfg file:

\Preamble{xhtml,fn-in,epub}
\RequirePackage{etoolbox}% for the \forsvlist command

\newcommand\ConfigurePar[1]{\realConfigurePar#1!}
\def\realConfigurePar#1/#2!{%
    \csdef{#1}##1{\HCode{<p class="#2">}##1\HCode{</p>\Hnewline}}%
}

\begin{document}
\forcsvlist\ConfigurePar{
  HalfTitle/TPHT,
  Title/TPT
}

\EndPreamble

together with the latex file

\documentclass{article}
\usepackage[english,czech]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\ProvidesPackage{epub}%
\usepackage{amsmath,amssymb}
\usepackage{endnotes}
\usepackage{epsfig}
\usepackage{graphicx}
\usepackage{latexsym}
\usepackage{multicol}
\usepackage{framed}%
\usepackage{glossaries}%
\usepackage[tex4ht]{hyperref}%
\def\toprule{\hline}%
\def\botrule{\hline}%
\def\midrule{\hline}%
\usepackage{listings}%
\usepackage{pgffor}% for the \foreach command
\newcommand{\HalfTitle}[1]{%
\Large#1%
}%

\newcommand{\Title}[1]{\Large#1}%
\begin{document}
\HalfTitle{Machine Learners}
\Title{Title}
\end{document}

produces the html file:

<?xml version="1.0" encoding="iso-8859-2" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd-->  
<html xml:lang="cs" xmlns="http://www.w3.org/1999/xhtml"  
> 
<head>
   <title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<!-- html,xhtml,fn-in,epub --> 
<meta name="src" content="s.tex" /> 
<link rel="stylesheet" type="text/css" href="s.css" /> 
</head><body 
>
<!--l. 26--><p class="noindent" ><p class="TPHT">Machine Learners</p> 
 <p class="TPT ">Title</p> 
 </p> 
</body></html> 

In particular, Machine Learners and Title are wrapped in paragraph tags with the expected classes. Also, I don't think that the 4ht file is necessary.

Btw, rather than using htlatex directly I recommend using make4ht package instead. To produce the html file above I used the command:

make4ht  -c epub.cfg sample.tex  
  • Thanks for the response. I used the code but still facing some issues. Can I attach the working sample files for your review with the updated config file through email? – christober C Jul 14 '17 at 11:04
  • HI Andrew, I have updated code but here issue is we are defining a command with some action like loop through the input (correct me if i am wrong). However we need to execute the command with argument like \ConfigurePar{ HalfTitle/TPHT, } before our \begin{document} then only it take and working. But not producing the expected result. Instead, producing blank tags like <p class="TPHT"></p>. Can you suggest me am i correct? – christober C Jul 14 '17 at 12:16
  • 1
    Can you please edit your original post and provide a full minimal working example so that I can properly test the code? You should provide a minimal latex file that compiles with (pdf)latex, together with a cfg file with your \Configure statements that can be run through tex4ht/make4ht. This makes it easier for people to test code against what you want. – Andrew Jul 14 '17 at 17:21
  • I have modified the question and added MWE for your review... – christober C Jul 15 '17 at 5:37
  • @Andrew you are amazing, your answer fully fit for my requirement also... – MadyYuvi Jul 17 '17 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.