![htlatex - 需要帮助将 latex 转换为 html](https://linux22.com/image/259435/htlatex%20-%20%E9%9C%80%E8%A6%81%E5%B8%AE%E5%8A%A9%E5%B0%86%20latex%20%E8%BD%AC%E6%8D%A2%E4%B8%BA%20html.png)
我正在尝试将一组 tex 文件转换为 html。附加的代码生成了完美的 pdf。但是使用 htlatex 时会出现以下错误。
我对 tex 了解不多,所以请尽可能详细地提供帮助。
错误:
l.259 --- TeX4ht warning --- \halign translated into linear text ---
! Missing number, treated as zero.
<to be read again>
\ar:cnt
l.259 ...rigraph.sequences}{Trigraph}{Replacement}
相关文件可见https://github.com/ramneek-handa/draft/source
以下是一个最简单的例子:
\documentclass[ebook,10pt,oneside,openany,final]{memoir}
\usepackage[american]
{babel} % needed for iso dates
\usepackage[iso,american]
{isodate} % use iso format for dates
\usepackage[final]
{listings} % code listings
\setcounter{totalnumber}{10}
% Base definitions for tables
\newenvironment{TableBase}
{
\renewcommand{\tcode}[1]{{\CodeStylex{##1}}}
\newcommand{\topline}{\hline}
\newcommand{\capsep}{\hline\hline}
\newcommand{\rowsep}{\hline}
\newcommand{\bottomline}{\hline}
%% vertical alignment
\newcommand{\rb}[1]{\raisebox{1.5ex}[0pt]{##1}} % move argument up half a row
%% header helpers
\newcommand{\hdstyle}[1]{\textbf{##1}} % set header style
\newcommand{\Head}[3]{\multicolumn{##1}{##2}{\hdstyle{##3}}} % add title spanning multiple columns
\newcommand{\lhdrx}[2]{\Head{##1}{|c}{##2}} % set header for left column spanning #1 columns
\newcommand{\chdrx}[2]{\Head{##1}{c}{##2}} % set header for center column spanning #1 columns
\newcommand{\rhdrx}[2]{\Head{##1}{c|}{##2}} % set header for right column spanning #1 columns
\newcommand{\ohdrx}[2]{\Head{##1}{|c|}{##2}} % set header for only column spanning #1 columns
\newcommand{\lhdr}[1]{\lhdrx{1}{##1}} % set header for single left column
\newcommand{\chdr}[1]{\chdrx{1}{##1}} % set header for single center column
\newcommand{\rhdr}[1]{\rhdrx{1}{##1}} % set header for single right column
\newcommand{\ohdr}[1]{\ohdrx{1}{##1}}
\newcommand{\br}{\hfill\break} % force newline within table entry
%% column styles
\newcolumntype{x}[1]{>{\raggedright\let\\=\tabularnewline}p{##1}} % word-wrapped ragged-right
% column, width specified by #1
% \newcolumntype{m}[1]{>{\CodeStyle}l{##1}} % variable width column, all entries in CodeStyle
\newcolumntype{m}[1]{l{##1}} % variable width column, all entries in CodeStyle
}
{
}
% General Usage: TITLE is the title of the table, XREF is the
% cross-reference for the table. LAYOUT is a sequence of column
% type specifiers (e.g. cp{1.0}c), without '|' for the left edge
% or right edge.
% usage: \begin{floattablebase}{TITLE}{XREF}{COLUMNS}{PLACEMENT}
% produces floating table, location determined within limits
% by LaTeX.
\newenvironment{floattablebase}[4]
{
\begin{TableBase}
\begin{table}[#4]
\caption{\label{#2}#1}
\begin{center}
\begin{tabular}{|#3|}
}
{
\bottomline
\end{tabular}
\end{center}
\end{table}
\end{TableBase}
}
% usage: \begin{floattable}{TITLE}{XREF}{COLUMNS}
% produces floating table, location determined within limits
% by LaTeX.
\newenvironment{floattable}[3]
{
\begin{floattablebase}{#1}{#2}{#3}{htbp}
}
{
\end{floattablebase}
}
\newcommand{\CodeStylex}[1]{\texttt{#1}}
\newcommand{\tcode}[1]{\CodeStylex{#1}}
\begin{document}
\begin{floattable}
{Potential \tcode{setlocale} data races}
{tab:setlocale.data.races}
{lllll}
\topline
\tcode{fprintf} &
\tcode{isprint} &
\tcode{iswdigit} &
\tcode{localeconv} &
\tcode{tolower} \\
\end{floattable}
\end{document}
答案1
好吧,由于缺乏对回忆录的支持,导致了一些错误tex4ht
。我们在另一个问题。现在您需要添加对宏的支持。为此,您应该将它们分开到包中,例如ramneek.sty
\setcounter{totalnumber}{10}
% Base definitions for tables
\newenvironment{TableBase}
{
\renewcommand{\tcode}[1]{{\CodeStylex{##1}}}
\newcommand{\topline}{\hline}
\newcommand{\capsep}{\hline\hline}
\newcommand{\rowsep}{\hline}
\newcommand{\bottomline}{\hline}
%% vertical alignment
\newcommand{\rb}[1]{\raisebox{1.5ex}[0pt]{##1}} % move argument up half a row
%% header helpers
\newcommand{\hdstyle}[1]{\textbf{##1}} % set header style
\newcommand{\Head}[3]{\multicolumn{##1}{##2}{\hdstyle{##3}}} % add title spanning multiple columns
\newcommand{\lhdrx}[2]{\Head{##1}{|c}{##2}} % set header for left column spanning #1 columns
\newcommand{\chdrx}[2]{\Head{##1}{c}{##2}} % set header for center column spanning #1 columns
\newcommand{\rhdrx}[2]{\Head{##1}{c|}{##2}} % set header for right column spanning #1 columns
\newcommand{\ohdrx}[2]{\Head{##1}{|c|}{##2}} % set header for only column spanning #1 columns
\newcommand{\lhdr}[1]{\lhdrx{1}{##1}} % set header for single left column
\newcommand{\chdr}[1]{\chdrx{1}{##1}} % set header for single center column
\newcommand{\rhdr}[1]{\rhdrx{1}{##1}} % set header for single right column
\newcommand{\ohdr}[1]{\ohdrx{1}{##1}}
\newcommand{\br}{\hfill\break} % force newline within table entry
%% column styles
\newcolumntype{x}[1]{>{\raggedright\let\\=\tabularnewline}p{##1}} % word-wrapped ragged-right
% column, width specified by #1
% \newcolumntype{m}[1]{>{\CodeStyle}l{##1}} % variable width column, all entries in CodeStyle
\newcolumntype{m}[1]{l{##1}} % variable width column, all entries in CodeStyle
}
{
}
% General Usage: TITLE is the title of the table, XREF is the
% cross-reference for the table. LAYOUT is a sequence of column
% type specifiers (e.g. cp{1.0}c), without '|' for the left edge
% or right edge.
% usage: \begin{floattablebase}{TITLE}{XREF}{COLUMNS}{PLACEMENT}
% produces floating table, location determined within limits
% by LaTeX.
\newenvironment{floattablebase}[4]
{
\begin{TableBase}
\begin{table}[#4]
\caption{\label{#2}#1}
\begin{center}
\begin{tabular}{|#3|}
}
{
% \bottomline
\end{tabular}
\end{center}
\end{table}
\end{TableBase}
}
% usage: \begin{floattable}{TITLE}{XREF}{COLUMNS}
% produces floating table, location determined within limits
% by LaTeX.
\newenvironment{floattable}[3]
{
\begin{floattablebase}{#1}{#2}{#3}{htbp}
}
{
\end{floattablebase}
}
\newcommand{\CodeStylex}[1]{\texttt{#1}}
\newcommand{\tcode}[1]{\CodeStylex{#1}}
现在您需要为 添加配置tex4ht
,因此创建文件ramneek.4ht
。当您使用包 ramneek 时,此文件会自动加载。
\NewConfigure{TableBase}{2}
\ConfigureEnv{TableBase}{%
\a:TableBase
}{\b:TableBase}{
\renewcommand\topline{}
\renewcommand\bottomline{}
}{}
\Configure{TableBase}{\HCode{<div class="TableBase">\Hnewline}}{\HCode{</div>\Hnewline}}
\Css{
.TableBase .tabular td{
border-top:1px solid black;
border-bottom:1px solid black;
}
}
此代码修补了环境TableBase
,重新定义了导致问题的宏\topline
,\bottomline
并插入了可配置的钩子。\Configure{TableBase}
我们配置此钩子以插入<div class=TableBase>
,并使用\Css
命令,您可以根据需要使用级联样式表配置表格的外观。