Open SamMachariaPhD opened 1 year ago
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.
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.
== 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.
== 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.
== 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>>.
\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}')
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
I'm testing the
asciidoctor-multipage
extension and want to generate asciidoctor HTML multipages. I'm also interested in PDF and one-page HTML. I made the following test documents attached here["test.adoc", "chap1.adoc", "chap2.adoc", "chap3.adoc"]
.test.adoc
chap1.adoc
chap2.adoc
chap3.adoc
Terminal commands
Having installed the required extension packages on Ubuntu 20.04, I used the following commands to generate the outputs in various directories.
All documents are generated successfully, except that, unlike in the PDF and the one-page HTML output, the
asciidoctor-multipage
HTMLs output seems to reset or forget the latex equation counter on every page. Every equation is labelled (1) even when the cross-reference correctly indicates Equation 3.I would like
asciidoctor-multipage
to remember the counter and match all equation labels as in (1) (2) (3) on various pages. Not (1) (1) (1). How do I force theasciidoctor-multipage
extension to preserve the latex equation numbering similar to the PDF and the one-page HTML?Thank you. Regards, Sam.