GithubHelp home page GithubHelp logo

How do I prevent asciidoctor-multipage from resetting the latex equation counter after every HTML Page? about asciidoctor-multipage HOT 3 OPEN

SamMachariaPhD avatar SamMachariaPhD commented on May 25, 2024
How do I prevent asciidoctor-multipage from resetting the latex equation counter after every HTML Page?

from asciidoctor-multipage.

Comments (3)

owenh000 avatar owenh000 commented on May 25, 2024

It looks like the equation numbers are added by the MathJax script when it runs during page load, and there is no numbering added by Asciidoctor that could be used to correctly number the equations. See this excerpt, the stem block, from the _chapter_2.html output:

<div id="eqn-normalStrain" class="stemblock">
<div class="content">
\[\begin{align}
\epsilon\ (\text{strain}) = \frac{\Delta L\ (\text{change in length})}{L\ (\text{original length})}
\end{align}\]
</div>
</div>

The MathJax script adds the equation numbers as configured in this excerpt, later in _chapter_2.html:

MathJax.Hub.Config({
  TeX: { equationNumbers: { autoNumber: "Equation" } }
})

As you can see, only Asciidoctor knows the reftext of the stem block. MathJax only knows the numbering prefix (and in this case apparently doesn't use it), but not the actual number. So it seems to me like it is not possible to fix this without changes to Asciidoctor. I'll leave this issue open here for now in case someone has opportunity to work on it.

from asciidoctor-multipage.

SamMachariaPhD avatar SamMachariaPhD commented on May 25, 2024

Thank you for your response @owenh000
Meanwhile, I decided to use the LaTex \tag{}. I also made a simple Python code to update an equation's tag because I did not want to update each tag manually. This may be a crude method, but it served the purpose.

Updated: chap1.adoc

== Chapter 1 

This is my chapter one. 

[stem#eqn-normalStress,reftext='{eqnums} {counter:eqnum}'] 
++++
\begin{align}\tag{#eqnum#}
\sigma\ (\text{stress}) = \frac{F\ (\text{load})}{A\ (\text{area})}\ \frac{N}{m^2}
\end{align}
++++

From <<#eqn-normalStress>>, you can calculate the normal stress. 

Updated: chap2.adoc

== Chapter 2 

This is a test chapter 2. 

[stem#eqn-normalStrain,reftext='{eqnums} {counter:eqnum}'] 
++++
\begin{align}\tag{#eqnum#}
\epsilon\ (\text{strain}) = \frac{\Delta L\ (\text{change in length})}{L\ (\text{original length})}
\end{align}
++++

From <<#eqn-normalStrain>>, you can calculate strain. 

Updated: chap3.adoc

== Chapter 3 

This is the final test chapter. 

[stem#eqn-twistShear,reftext='{eqnums} {counter:eqnum}'] 
++++
\begin{align}\tag{#eqnum#}
\text{Shear strain, } \gamma = \frac{R\theta}{L} 
\end{align}
++++

Calculate shear strain from <<#eqn-twistShear>>.

Python Code to Update \tag{#eqnum#}

main_file = "test.adoc"
start_key_word = "include::"
end_key_word = ".adoc["
eqn_tag = "#eqnum#"
eqn_count = 1

bool_write_line = False
file_names = [main_file[:-5]] # remove .adoc extension

############get all file names as included###############

with open(main_file) as infile:
    for line in infile:
        if line.startswith(start_key_word):
            bool_write_line = end_key_word in line
        if bool_write_line:
            line = line.split(end_key_word)[0]
            line = line.split(start_key_word)[1]
            file_names.append(line)
            bool_write_line = False

############update equation tags###############

for i in range(len(file_names)):
    file_path = file_names[i]+".adoc"

    infile = open(file_path, 'r')
    lines =  infile.readlines()

    for i in range(len(lines)):
        if eqn_tag in lines[i]:
            #print(lines[i]) # original tag
            nl = lines[i].replace(eqn_tag, str(eqn_count))
            lines[i] = nl
            #print(lines[i]) # replaced tag 
            eqn_count += 1

    with open(file_path, 'w') as filehandle:
        for listitem in lines:
            filehandle.write(f'{listitem}')

from asciidoctor-multipage.

owenh000 avatar owenh000 commented on May 25, 2024

Hi Sam, thanks for sharing your workaround. It might be possible to improve this behavior by doing the following in asciidoctor-multipage: (1) disabling MathJax auto-numbering and (2) adding an explicit Latex tag{} in each case. Since there isn't (as far as I know) an "equation number" in Asciidoctor, it would use the reftext value as the tag. But it might be too fragile, require changes to Asciidoctor, and/or break with unrelated upstream changes.

Note :eqnums: only takes three values; see the Document Attributes Reference. It looks like it just gets reset to AMS.

Edit: removed a stray parenthesis

from asciidoctor-multipage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.