transpect/docx2tex

Is it possible to change the inline math delimiter?

mjr opened this issue ยท 4 comments

mjr commented

The image below shows 3 latex options for inline math delimiter, is it possible to pass a parameter to define which one to use?

Screen Shot 2022-09-12 at 20 53 06

Image ref: https://www.overleaf.com/learn/latex/Mathematical_expressions#Inline_math_mode

It's a possible but a bit more complicated since some mappings in our character map contain already Dollar characters. Unfortunately, I'm very busy at the moment, so I cannot give you a time frame for resolving this issue.

mjr commented

@mkraetke Would it be simpler if I made a fork and replaced the character map of $ with $$ or something similar?

I'm wanting to do this because I'm wanting to identify where there are inline formulas, but it gets more complicated because the dollar might not be a formula. (ex: $500, $400)

Perhaps it's not necessary to fork the entire project. You can just create your own configuration and import the docx2tex configuration. Then you could just overwrite the things you don't like and use the command line parameter -c to pass the path to your custom configuration. Here is a sample configuration that would be sufficient:

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns="http://transpect.io/xml2tex"  
     xmlns:tr="http://transpect.io"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <import href="docx2tex/conf/conf.xml"/>
  
  <!-- override lines 742 to 749 of docx2tex/conf/conf.xml
       applies to real Word equations which are treated by 
       our mml2tex module -->

  <template context="dbk:inlineequation[not(ancestor::dbk:superscript or ancestor::dbk:subscript )]
                    |dbk:equation[ancestor::dbk:table or ancestor::dbk:informaltable]">
    <rule>
      <text select="'\begin{math}'"/>
      <text/>
      <text select="'\end{math}'"/>
    </rule>
  </template>
  
  <!-- selectively override the character mappings. Please 
       note that this apply to text characters outside of equations. -->
  
  <charmap ignore-imported-charmaps="false">
    <!--DEGREE SIGN -->
    <char character="&#xb0;" string="\begin{math}\circ\end{math}"/>
  </charmap>
  
</set>
mjr commented

@mkraetke Thank you very much, it worked perfectly.