Настройка существующих однострочных классов в выводе ODT из mk4ht oolatex

Aug 18 2020

В качестве расширения этого вопроса: Создание новых однострочных классов в выводе ODT из mk4ht oolatex

Я пытался использовать этот подход для переназначения стиля, назначенного в существующих командах, которые уже были настроены. Первоначальное руководство, представленное в комментариях к связанному вопросу, предлагало начать с \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. Я удалил код TeX, например, \TitleMarkи \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"
  • или как часть файла bat в Windows: "%MikTexPath%%htxCompiler%" --config "myconfig.cfg" --format "odt+odttemplate" "%%~nxA" odttemplate="./refTemplates/basic.odt"

Если я полностью промахнулся, как еще я мог изменить сопоставление стилей в существующих командах?

Ответы

1 michal.h21 Aug 18 2020 at 02:59

Я получаю ошибки с вашим 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}, потому что это привело к ложному пустому абзацу , который показал в документе.

Это визуализированный документ: