htlatex를 사용하여 생성된 mathml의 잘못된 태그 순서

htlatex를 사용하여 생성된 mathml의 잘못된 태그 순서

대규모 수학 문서를 라텍스에서 html + mathml로 변환하고 있습니다. 어떤 상황에서는 출력 파일의 모양이 잘못되었습니다. 예는 다음과 같습니다.

메인 파일test.tex이다:

\documentclass{article}

\begin{document}
\[
  X \mbox{ is \emph{dense in $Y$}}
\]
\end{document}

최소한의 구성myconfig.cfg파일은 다음과 같습니다:

\Preamble{mathml}

\Configure{emph}{\ifvmode\ShowPar\fi\HCode{<em>}}{\HCode{</em>}}

\begin{document}
\EndPreamble

이제 명령을 실행해 보세요.htlatex 테스트.tex myconfig.cfg나는 (서문을 제거하고 코드를 재구성한 후) 다음을 얻습니다.

<body>  
   <div class="par-math-display"><!--l. 5--><math 
 xmlns="http://www.w3.org/1998/Math/MathML"  
display="block" >
<mrow>
   <mi>X</mi>
<mstyle class="mbox">
<!--error-->   <mtext>&#x00A0;is&#x00A0;
<!--error-->   <em>dense&#x00A0;in&#x00A0;
<!--error-->   </mtext>
  <mstyle class="math">
    <mi>Y</mi>
  </mstyle>
<mtext>
<!--error-->   </em>
</mtext></mstyle>
</mrow></math></div>
<!--l. 7--><p class="nopar" >  
</body>

이 출력에서 ​​여는 태그와 닫는 태그는여러 줄 문자그리고여자 이름내가 강조한 것은 중첩되지 않고 인터리브되어 있습니다.

라텍스 코드를 수정하는 것은 선택 사항이 아니라는 점을 추가하겠습니다(큰 코드 조각으로 인해). 그럼에도 불구하고 가능한 것은 \emph를 재정의하는 것입니다(그러나 제가 시도한 다양한 재정의로는 출력이 변경되지 않았습니다).

답변1

편집하다:

<mtext>형식 지정 명령이 사용될 때 실제로 요소를 생성하는 업데이트된 구성은 다음과 같습니다 .

\Preamble{xhtml,mathml,fonts}
\catcode`\:=11
\makeatletter
\newcommand\providemtextclass[1]{%
  \Configure{@mtext}{#1}%
  \HCode{</mtext>}\ht:special{t4ht@,}\HCode{<mtext \a:@mtext>}\ht:special{t4ht@,&\#x00A0;}%
}
\catcode`\:=12
\makeatother

\begin{document}
\Configure{emph} {\ifmathml\providemtextclass{class="emph" mathvariant="italic" }\else \HCode{<em>}\NoFonts\fi}{\ifmathml\else\EndNoFonts \HCode{</em>}\fi}
\EndPreamble

명령 \providemtextclass이 조금 복잡합니다. 다음 <mtext>요소 에서 사용해야 하는 속성을 정의합니다 . 실제로 열린 를 닫아야 합니다 <mtext>. 이 \ht:special명령은 에 특별한 지침을 제공합니다 tex4ht. 는 \ht:special{t4ht@,&\#x00A0;}공백을 깨지지 않는 공백으로 바꾸는 데 사용됩니다. 그렇지 않으면 단어가 함께 축소되기 때문에 MathML 텍스트에 필요합니다. 하지만 태그를 인쇄할 때는 비활성화해야 합니다. 잘못된 XML 구조가 생성되기 때문입니다. 를 사용하여 비활성화할 수 있습니다 \ht:special{t4ht@,}.

렌더링된 결과:

여기에 이미지 설명을 입력하세요

그리고 MathML:

<math display='block' xmlns='http://www.w3.org/1998/Math/MathML'><mrow>
                                         <mi>X</mi><mstyle class='mbox'><mtext> is </mtext><mtext class='emph' mathvariant='italic'>dense in </mtext><mstyle class='math'><mi>Y</mi> </mstyle><mtext class='emph' mathvariant='italic'></mtext></mstyle>
</mrow></math>

원래 답변:

명령 구성은 \emph수학 내부에서 사용될 때 상황을 고려해야 합니다. MathML그렇지 않으면 유효하지 않게 됩니다.

다음은 다음에서 제공되는 수정된 구성 버전입니다 mathml.4ht.

\Preamble{xhtml,mathml,fonts}
\Configure{emph}
{\ifmathml \Configure{@mtext}{ class="emph"
mathvariant="italic" }%
\else \HCode{<em>}\NoFonts\fi}
{\ifmathml\else\EndNoFonts \HCode{</em>}\fi}
\begin{document}
\EndPreamble

기본 텍스트 명령은 <mtext>MathML에서 요소를 생성하며 를 사용하여 해당 속성을 설정할 수 있습니다 \Configure{@mtext}. 이 구성은 스위치 덕분에 수학 환경 내에서 사용됩니다 \ifmathml. 일반 텍스트에서는 <em>가 사용됩니다.

그러면 다음과 같은 결과가 생성됩니다.

<div class='par-math-display'><!-- l. 4 --><math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><mrow>
                                         <mi>X</mi><mstyle class='mbox'><mtext> is dense in </mtext><mstyle class='math'><mi>Y</mi> </mstyle><mtext class='emph' mathvariant='italic'></mtext></mstyle>
</mrow></math></div>

가짜가 있음을 알 수 있습니다 <mtext class='emph' mathvariant='italic'></mtext>. 명령 $Y$에 포함하면 발생합니다 \emph. 이 버전이 더 잘 작동합니다.

 X \mbox{ is \emph{dense in }$Y$}

마지막 질문에 관해서. 다음 위치에 버그 추적기와 소스 코드 저장소가 있습니다.푸슈차. 오류는 소스에서 직접 수정되고 업데이트는 TeX 배포판으로 직접 이동됩니다.

TeX.sx에 대한 질문의 큰 부분은 실제로 버그가 아니라 특정 사용자 요구에 맞게 출력을 수정하는 것에 대한 더 많은 질문이므로 패키지로 제공하는 것은 실제로 의미가 없습니다. 일반적인 문제 및 구성 목록을 제공하면 좋을 것입니다. 사실 문서도 업데이트해야 합니다. 나는 시작했다일하는 중입니다, 그러나 진행 속도가 느립니다. 나에게는 산문보다 코드를 작성하는 것이 훨씬 쉽습니다. 특히 저는 영어가 모국어가 아니기 때문입니다. 나는 또한 새로운 make4ht 및 tex4ebooks 버전을 작업하느라 바빠서 문서화할 시간을 실제로 찾을 수 없습니다.

관련 정보