2

i'm beginner in Tex and i have tex file

\documentclass{article}

\addtolength{\jot}{1em}

\begin{document}
\begin{verbatim}
\end{verbatim}
\begin{chestnutStem}
In the following figure, if the spinner is divided into 8 colored sections, what is the probability of it stopping at blue?

\centerline{\includepdf[page=2]{mypdf.pdf}}

\end{chestnutStem}

\chestnutKey{
$        \frac{1}{4}      $
}

\begin{chestnutAnswer}

        \begin{align*}
        \textrm{The probability of the spinner stopping at blue}&=\frac{\textrm{the number of blue sections}}{\textrm{total number of sections}}\\
        &=\frac{2}{8}\\
        &=\frac{1}{4}.
        \end{align*}

\end{chestnutAnswer}

\end{document} 

and i have cls file

\ProvidesClass{chestnut}[2016/02/17]
\LoadClass{article}
\RequirePackage{amsmath}
\RequirePackage{kvoptions}
\RequirePackage{graphicx}
\RequirePackage{xkeyval}
\DeclareStringOption{country}{}
\DeclareStringOption{language}{}
\DeclareStringOption{math}{}
\DeclareStringOption{numerals}{}
\ProcessKeyvalOptions*\relax

\DeclareOption{example}{%
\typeout{You are using example object.}

}%

\DeclareOption*{}{}
\ProcessOptions*\relax

\RequirePackage[lmargin=0.5in,rmargin=0.5in,tmargin=0.5in,bmargin=0.5in]{geometry}
\let\country=\chestnut@country
\typeout{ Your country \country}

\let\language=\chestnut@language
\typeout{ Your language \language}

\let\math=\chestnut@math
\typeout{ Your symbols language is \math}

\let\numerals = \chestnut@numerals
\typeout{ Your numerals are in \numerals}

\newenvironment{chestnutStem}{\underline{\textbf{Stem}}\\* }{\hfill \\* }

\newcommand\chestnutKey[1]{\underline{\textbf{Key}}\\*#1\hfill\\* }

\newenvironment{chestnutAnswer}{\underline{\textbf{Answer}}\\*}{\hfill \\* }

\RequirePackage{alternative4ht}
\altusepackage{pdfpages}
\newcommand\chestnutTikZ[1]{\includepdf[pages=-,width=.9\textwidth]{#1}}

\setlength{\parindent}{0pt}
\pagenumbering{gobble}
\IfFileExists{approved.jpg}{%
\RequirePackage{fancyhdr}
\renewcommand\headrule{}
\rhead{\vspace{0.5in}\includegraphics[scale=0.2]{approved.png}}
\pagestyle{fancy}
}%

and alternative4ht.sty file

\ProvidesPackage{alternative4ht}

\newcommand{\altusepackage}[2][]{%
    \ifx\HCode\relax%
    \usepackage[#1]{#2}%
    \else%
    \IfFileExists{#2-alt4ht.sty}{%
      \usepackage[#1]{#2-alt4ht}%
    }{\typeout{alternative4ht: no patch file for #2}}
    \fi%
}
\endinput

and pdfpages-alt4ht.sty file

\ProvidesPackage{pdfpages-alt4ht}
\RequirePackage{graphicx}

\newcommand\includepdf[2][]{%
    \includegraphics{#2}
}

\endinput

and cfg file to convert pdf pages to png images

\Preamble{xhtml}
  \Configure{graphics*}  
         {pdf}  
         {\Needs{"convert -scene 1 \csname Gin@base\endcsname.pdf  
                               \csname Gin@base\endcsname.png"}%  
          \Picture[pict]{\csname Gin@base\endcsname .png}% here i want add page number with pdf file name for example <mypdf-2.png>
          \special{t4ht+@File: \csname Gin@base\endcsname.png}
         }  
\begin{document}
\EndPreamble

I want get [page] value option in \includepdf command to use it in config file

  • Welcome to TeX.SX. Sorry, your question is totally unclear! Your example seems to be some special markup that creates a LaTeX file – user31729 Mar 22 '16 at 22:46
  • 2
    Welcome to TeX.SX!! It is better to post a full minimal working example that starts with a \documentclass command, has a minimal preamble and then \begin{document}...\end{document}. Unless the problem is a compilation error, the code should compile and be as small as possible to demonstrate your problem. This makes it much easier for people to help you --- and much more likely that they will! In this case you should point out that this is a tex4ht issue. – Andrew Mar 23 '16 at 0:26
  • Your question poses more questions than you might realize. Here are some: How did you come to have this command? How did you come to have a .cfg file? What does it configure, exactly? Is your \includepdf command from pdfpages? Please read the link Andrew posted and edit your question accordingly. – jon Mar 23 '16 at 1:19
  • why do you have \begin{verbatim} \end{verbatim} in there? – Nasser Mar 26 '16 at 4:33
  • @Nasser to include meta-data i need it – Shams Mar 27 '16 at 9:31
2

pdfpages is one of packages which causes tex4ht to fail once they are included. In this case, TeX source must be altered, which is something that we try to avoid with tex4ht. helpers4ht bundle provides \altusepackage command, which can be used to load alternative version of packages for tex4ht. These alternative packages are named packagename-alt4ht.sty. They contain definitions for macros used in the document. Definition for pdfpages was only basic, it could be used to include only one paged pdf document.

To support multipage pdf files, I've added pages option to \includepdf command in pdfpages-alt4ht.sty package. It doesn't support all features of original, as it would be quite difficult to implement it and I don't think that it makes sense in HTML output:

\ProvidesPackage{pdfpages-alt4ht}
\RequirePackage{graphicx}
\RequirePackage{xkeyval}
\define@key{includepdf}{pages}{\edef\current@pdf@page{\the\numexpr #1-1\relax}}

\newcommand\includepdf[2][]{%
  \def\current@pdf@page{0}
    \setkeys*{includepdf}{#1}
    \filename@parse{#2}
    \def\current@png@name{\filename@area\filename@base-\current@pdf@page.png}
    \IfFileExists{\current@png@name}{}{%
      \Needs{"convert #2[\current@pdf@page]
      \current@png@name"}
    }
    \includegraphics{\current@png@name}
  }

  \endinput

it saves requested page in \current@pdf@page macro, it must be decremented by 1, because imagemagick counts pages from 0. The png name is constructed as imagename-pagenumber.png and convert program is called only if it doesn't exist yet.

I had to fix one issue in chestnut.cls, there was missing {} in IfFileExists:

\ProvidesClass{chestnut}[2016/02/17]
\LoadClass{article}
\RequirePackage{amsmath}
\RequirePackage{kvoptions}
\RequirePackage{graphicx}
\RequirePackage{xkeyval}
\DeclareStringOption{country}{}
\DeclareStringOption{language}{}
\DeclareStringOption{math}{}
\DeclareStringOption{numerals}{}
\ProcessKeyvalOptions*\relax

\DeclareOption{example}{%
\typeout{You are using example object.}

}%

\DeclareOption*{}{}
\ProcessOptions*\relax

\RequirePackage[lmargin=0.5in,rmargin=0.5in,tmargin=0.5in,bmargin=0.5in]{geometry}
\let\country=\chestnut@country
\typeout{ Your country \country}

\let\language=\chestnut@language
\typeout{ Your language \language}

\let\math=\chestnut@math
\typeout{ Your symbols language is \math}

\let\numerals = \chestnut@numerals
\typeout{ Your numerals are in \numerals}

\newenvironment{chestnutStem}{\underline{\textbf{Stem}}\\* }{\hfill \\* }

\newcommand\chestnutKey[1]{\underline{\textbf{Key}}\\*#1\hfill\\* }

\newenvironment{chestnutAnswer}{\underline{\textbf{Answer}}\\*}{\hfill \\* }

\RequirePackage{alternative4ht}
\altusepackage{pdfpages}
\newcommand\chestnutTikZ[1]{\includepdf[pages=-,width=.9\textwidth]{#1}}

\setlength{\parindent}{0pt}
\pagenumbering{gobble}
\IfFileExists{approved.jpg}{%
\RequirePackage{fancyhdr}
\renewcommand\headrule{}
\rhead{\vspace{0.5in}\includegraphics[scale=0.2]{approved.png}}
\pagestyle{fancy}
}{}%

and also your TeX file, because chestnut class wasn't used:

\documentclass{chestnut}

\addtolength{\jot}{1em}

\begin{document}
\begin{verbatim}
\end{verbatim}
\begin{chestnutStem}
In the following figure, if the spinner is divided into 8 colored sections, what is the probability of it stopping at blue?

\centerline{\includepdf[pages=2]{mypdf.pdf}}

\end{chestnutStem}

\chestnutKey{
$        \frac{1}{4}      $
}

\begin{chestnutAnswer}

        \begin{align*}
        \textrm{The probability of the spinner stopping at blue}&=\frac{\textrm{the number of blue sections}}{\textrm{total number of sections}}\\
        &=\frac{2}{8}\\
        &=\frac{1}{4}.
        \end{align*}

\end{chestnutAnswer}

\end{document} 

sample output:

enter image description here

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.