从 mk4ht oolatex 自定义 ODT 输出中的现有单行类

从 mk4ht oolatex 自定义 ODT 输出中的现有单行类

作为这个问题的扩展: 从 mk4ht oolatex 在 ODT 输出中创建新的单行类

我一直在尝试使用此方法重新分配已配置的现有命令中指定的样式。链接问题的评论中提供的初步指导建议\Configure{section}ooffice.4ht

\Configure{section}
   {\IgnorePar\EndP \HCode{<!--start of section-->}}
   {\IgnorePar\EndP \HCode{<!--end of section-->}}
   {\HCode{<text:h
            text:style-name="\csname a:Heading-2\if@rl-rtl\fi
\endcsname"
                   \text:outlinelevel="2" ><text:span
                   text:style-name="section" >}\TitleMark\space
    \HCode{</text:span>}\IgnoreIndent}
   {\HCode{</text:h>\Hnewline}\par\ShowPar}

因此我开始尝试使用这个块作为起点。但是我无法编译这个块,更不用说用我自己的样式名称进行自定义了。我尝试了许多排列和范围更改来详细说明每个排列和范围更改,但简而言之,我尝试过:

  1. 简化该csname行以仅包含我想要的部分名称。
  2. 我已经删除了像\TitleMark和这样的TeX 代码\space
  3. 我还尝试用根据相关问题的答案启发而HCode定制的文本替换这些部分。HCode
  4. 我的设置似乎对空格很敏感,所以我一直在研究这个问题以及%行尾的问题。

我有时会收到有关:h和相关>字符的错误消息,但一般来说它只报告典型的Missing \begin{document} in myconfig.cfg

梅威瑟:

测试.tex

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{xcolor}
\definecolor{specialtextcolor}{rgb}{0,0,1}

\newenvironment{test}
{\par\begin{color}{specialtextcolor}}
{\end{color}}


\usepackage[parfill]{parskip}

\usepackage{longtable}

\usepackage{graphicx}
\usepackage[export]{adjustbox}
    
\begin{document}
    
This is a normal paragraph.

\section{Custom style access test}

test text in the first level of section hierarchy 

more text

\begin{test}
    This is a test environment.
\end{test}    

more text

This is a blockquote environment

\begin{quote}
    This is a test quote environment.
\end{quote}    
    
\end{document}

我的配置文件

\Preamble{xhtml}
% to simplify the things
\def\myendpar{\ifvmode\IgnorePar\fi\EndP}

% configure the single line commands in Tex against their corresponding style in the template

\Configure{section}%
{\IgnorePar\EndP \HCode{<!--start of section-->}}%
{\IgnorePar\EndP \HCode{<!--end of section-->}}%
{\HCode{<text:h
        text:style-name="Heading-2">
        text:outlinelevel="2" ><text:span
        text:style-name="section" >}%
    %\TitleMark\space%
    \HCode{</text:span>}%
    %\IgnoreIndent%
}%
{\HCode{</text:h>\Hnewline}\par\ShowPar}%


% configure the environments in Tex against their corresponding style in the template
\ConfigureEnv{test}%
{%
    \myendpar\bgroup%
    % when you want to modify the paragraph style, you must redefine the paragraph configuration to use the test style name
    \Configure{HtmlPar}%
        {\EndP \HCode{<text:p text:style-name="test">}}%
        {\EndP \HCode{<text:p text:style-name="test">}}%
        {\HCode{</text:p>}}%
        {\HCode{</text:p>}}%
    \par\ShowPar%
}{\myendpar\egroup}{}{}%


\ConfigureEnv{quote}%
{%
    \myendpar\bgroup%
    % when you want to modify the paragraph style, you must redefine the paragraph configuration to use the test style name
    \Configure{HtmlPar}%
        {\EndP \HCode{<text:p text:style-name="quote">}}%
        {\EndP \HCode{<text:p text:style-name="quote">}}%
        {\HCode{</text:p>}}%
        {\HCode{</text:p>}}%
    \par\ShowPar%
}{\myendpar\egroup}{}{}%




\begin{document}

\EndPreamble

该示例使用以下命令针对示例 ODT 模板文件进行编译:

  • 作为 Linux Shell 脚本的一部分:make4ht -u --config "myconfig.cfg" --format "odt+odttemplate" "$FILE" odttemplate="$BASEDIR/refTemplates/basic.odt"
  • 或者作为 Windows 上的 bat 文件的一部分:"%MikTexPath%%htxCompiler%" --config "myconfig.cfg" --format "odt+odttemplate" "%%~nxA" odttemplate="./refTemplates/basic.odt"

如果我完全错过了目标,我还能怎样改变现有命令中的样式映射?

答案1

我收到错误的mwe.cfg主要原因是:您使用了未声明的\Configure{SectionTitleTest}并且因为缺少第五个参数\Configure{section}

我可以使用以下修复程序来编译您的文件:

\Preamble{xhtml}
% to simplify the things
\def\myendpar{\ifvmode\IgnorePar\fi\EndP}

% configure the single line commands in Tex against their corresponding style in the template

%\Configure{SectionTitleTest}{\myendpar\HCode{<text:p text:style-name="section-title">}}{\HCode{</text:p>}}
\NewConfigureOO{section-title}
\ConfigureOO{section-title}{<style:style style:name="section-title" style:family="paragraph" style:class="text">
    <style:text-properties style:text-underline-style="solid"   
    style:text-underline-width="auto"
    style:text-underline-color="font-color"   
    />
    </style:style>}


\Configure{section}%
{\IgnorePar\EndP \HCode{<!--start of section-->}}%
{\IgnorePar\EndP \HCode{<!--end of section-->}}%
{\HCode{<text:h
        text:style-name="Heading 1"
        text:outlinelevel="2" ><text:span
        text:style-name="section" >}%
    %\TitleMark\space%
    \HCode{</text:span>}%
    %\IgnoreIndent%
}{\HCode{</text:h>}}%

% \Configure{section}
%    {\IgnorePar\EndP \HCode{<!--start of section-->}}
%    {\IgnorePar\EndP \HCode{<!--end of section-->}}
%    {\HCode{<text:h
%             text:style-name="\csname a:Heading-2\if@rl-rtl\fi\endcsname"
%                    text:outlinelevel="2" ><text:span
%                    text:style-name="section" >}\TitleMark\space
%     \HCode{</text:span>}\IgnoreIndent}
%    {\HCode{</text:h>\Hnewline}\par\ShowPar}


% configure the environments in Tex against their corresponding style in the template
\ConfigureEnv{test}%
{%
    \myendpar\bgroup%
    % when you want to modify the paragraph style, you must redefine the paragraph configuration to use the test style name
    \Configure{HtmlPar}%
        {\EndP \HCode{<text:p text:style-name="test">}}%
        {\EndP \HCode{<text:p text:style-name="test">}}%
        {\HCode{</text:p>}}%
        {\HCode{</text:p>}}%
    \par\ShowPar%
}{\myendpar\egroup}{}{}%


\ConfigureEnv{quote}%
{%
    \myendpar\bgroup%
    % when you want to modify the paragraph style, you must redefine the paragraph configuration to use the test style name
    \Configure{HtmlPar}%
        {\EndP \HCode{<text:p text:style-name="quote">}}%
        {\EndP \HCode{<text:p text:style-name="quote">}}%
        {\HCode{</text:p>}}%
        {\HCode{</text:p>}}%
    \ShowPar%
}{\myendpar\egroup}{}{}%


\begin{document}

\EndPreamble

\par我添加的另一个修复是从中删除\ConfigureEnv{quote},因为这导致文档中显示虚假的空段落。

这是呈现的文档:

在此处输入图片描述

相关内容