การปรับแต่งคลาสบรรทัดเดียวที่มีอยู่ในเอาต์พุต 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 ตัวอย่างด้วยคำสั่ง:

  • เป็นส่วนหนึ่งของสคริปต์เชลล์ลินุกซ์: 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}เพราะนี้ส่งผลให้ในวรรคที่ว่างเปล่าปลอมที่แสดงให้เห็นในเอกสาร

นี่คือเอกสารที่แสดงผล: