mk4htoolatexからのODT出力で既存の単一行クラスをカスタマイズする

Aug 18 2020

この質問の拡張として: mk4htoolatexからの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

MWE:

test.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}

myconfig.cfg

\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シェルスクリプトの一部として: 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 michal.h21 Aug 18 2020 at 02:59

mwe.cfg主に次の理由でエラーが発生します:undeclaredを使用\Configure{SectionTitleTest}し、の5番目の引数が欠落しているため\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

私が追加したもう1つの修正は、から削除\parした\ConfigureEnv{quote}ことです。これにより、ドキュメントに偽の空の段落が表示されたためです。

これはレンダリングされたドキュメントです: