-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to force equations to right of cell when using tableEqns? #343
Comments
Not entirely sure what you're trying to achieve. A picture could be helpful. |
Hmm. The intention was for the cell with the equation number to be much narrower, so that the equation ends up being roughly centred. Something evidently goes wrong. AFAIU, you're targeting docx? What are you using to open the docx file? If I understand correctly, the principal aim is to have the equation is in the horizontal centre of the page and the number is right-aligned, correct? |
That's right, docx; and I'm using Word to open the docx file.
That is correct, yes. |
Which Word version, specifically? 365? What OS? |
Word version 16.58 (via a 365 subscription) on MacOS 11.4 (Big Sur). |
Thanks. I'll see what I can figure out. |
The bad news is I wasn't able to reproduce the rendering you're getting, unfortunately I have neither macOS nor Office 365 readily accessible. Where I tested (web version of Word 365, LibreOffice, Word 2013 and 2019 on Windows), it seemed to render more or less as expected. The good news is, I've made the NB: I think I might have messed up vertical alignment of equation numbers in tables, I'll see to fixing it later. Right-aligning can be done with the following metadata for example: tableEqns: true
eqnBlockTemplate: |
--------------------------------------------------------------- -------
$$t$$ $$i$$
--------------------------------------------------------------- -------
eqnBlockInlineMath: true (the extra newline in the table is important!) You need If you don't mind tinkering a bit, I believe the option of using tab stops to align equations should work the best in general, e.g. tableEqns: true
eqnBlockTemplate: |
`<w:pPr><w:tabs><w:tab w:val="center" w:pos="4680" /><w:tab w:val="right" w:pos="9360" /></w:tabs></w:pPr><w:r><w:tab /></w:r>`{=openxml} $$t$$ `<w:r><w:tab /></w:r>`{=openxml} $$i$$
eqnBlockInlineMath: true You'd have to manually specify tab stop positions, though (the values here, |
Ah, right, vertical alignment can be fixed with eqnBlockTemplate: |
+---------------------------------------------------------------:+-----:+
| ```{=openxml} | ```{=openxml}
| <w:tcPr><w:vAlign w:val="center"/></w:tcPr> | <w:tcPr><w:vAlign w:val="center"/></w:tcPr>
| ``` | ```
| $$t$$ | $$i$$
+----------------------------------------------------------------+-----+ Not pretty, but seems to work. |
I'd originally posted here that it didn't work, but I made a mistake: I wasn't using the new binary! I changed to using it, and then all worked great! Pandoc-crossref has been a lifesaver for me and I really appreciate your work on it! |
I should add that only the tab stop solution seemed to work for me. But it worked, and I'm grateful! |
As I mentioned above, this was the only solution that worked for me. But I've just noticed that this solution forces the equation to be displayed "in line" by which I mean, for example, that the limits above and below summation notation are set to the right of the summation sign, like this: If I change the display manually to fix the placement of notation above the summation, it forces the equation number below the equation, like this: |
In the '*.docx' file, the right-aligned equation numbering would look better using <m:eqArr>. Here are sample files to show the difference in displaying the equation number. The equation part in the origin file is:
And, the equation part using the <m:eqArr> modifier:
I have recommended this solution to tomduck/pandoc-eqnos. I am wondering whether it is a good choice. |
@llyu, unfortunately, unless we're willing to parse LaTeX ourselves and convert it to OOXML (which is very involved), there's no way to produce |
I found a nearly perfect solution to format equations in a .docx file. First, set the following options when output equationNumberTeX: \\#
eqnIndexTemplate: ($$i$$) Second, in the generated .dox file, use this macro: Sub EquationBookmark()
' Convert equations to professional format
ActiveDocument.OMaths.BuildUp
' Add Bookmarks to equations
' eq:# style is not supported
' eq# is used
Dim eq As OMath
Dim i As Long
Dim s As String
i = 1
For Each eq In ActiveDocument.OMaths
If eq.Type <> wdOMathInline Then
s = "eq" & CStr(i)
With ActiveDocument.Bookmarks
.Add Range:=eq.Range, Name:=s
.DefaultSorting = wdSortByLocation
.ShowHidden = False
End With
i = i + 1
End If
Next eq
' Auto-generated eq:# hyperlinks
' must be converted to eq#
Dim h As Hyperlink
For Each h In ActiveDocument.Hyperlinks
If InStr(1, h.SubAddress, "eq:") = 1 Then
Dim Rng As Range
Dim StrAddr As String, StrSubAddr As String
Dim SStrTxt As String
With h
Set Rng = .Range
StrAddr = .Address
StrSubAddr = .SubAddress
StrTxt = .TextToDisplay
.Delete
End With
StrSubAddr = Replace(StrSubAddr, "eq:", "eq")
ActiveDocument.Hyperlinks.Add Anchor:=Rng, Address:=StrAddr, SubAddress:=StrSubAddr
i = i + 1
End If
Next h
End Sub Now, everything will be perfect. I use Microsoft Word's native #(number) feature to add equation numbers, but equations must be in professional mode. Auto-generated bookmarks will be lost after conversion. I have some issues with the bookmarks at first. Not sure, how pandoc added So, I add |
Does this solution give you equation numbers on the right while allowing equations to be displayed in full "Display" mode, so that (for example) notation can be placed above and below a sigma summation symbol, rather than inline to the right of it? |
Yes, it does. It just uses Microsoft Word's native support for equation numbers (I am using 365) which works quite well. You can try it by inserting an equation in Word, adding Converting to professional mode is an alternative to typing an Before applying the macro: After applying the macro: The Macro above has some problems with inline maths, as it will add bookmarks to inline equations as well. I will update it to omit inline equations. |
Hi again! I'm sorry, but I'm still trying to navigate the issue I raised up above here. When using pandoc-crossref to output to a docx file, I can align the equation numbers to the right nicely with |
I don't have good news 🤷 If the clever hack suggested by @joezhouchenye doesn't work for you, I can't suggest anything else. I've tried to understand how Word handles |
Thanks. I wonder if @joezhouchenye would be able to walk me through how to use his macro? @joezhouchenye, when you write "I use Microsoft Word's native #(number) feature to add equation numbers," does that mean that I can't just apply the macro to the docx document that is produced by pandoc using pandoc-crossref? Thanks! |
This is what I mean by the native word feature. The equation must be in the syntax like The Macro does such conversion automatically and fixes the equation hyperlinks. To use this Macro, pandoc and pandoc-crossref need to convert markdown to the above syntax required. Luckily, pandoc-crossref offers two options So, the basic steps are:
|
Got it, thanks for that walk-through @joezhouchenye! I will try to implement this. Do you know if you ended up updating the macro to play nice with inline math? |
I just got this to work and all I can say is THANK YOU, @joezhouchenye!!!! I haven't check through the document to see how it does with inline math. Will report back! UPDATE: I can't see any issues with inline math. Hooray!! |
Hi again @joezhouchenye: This method has been working wonderfully for me, so thanks again! But I've just run into one glitch (or at least I think it's a glitch). When I run the macro, fractions that have skewed fractions as their numerator and/or denominator are being changed so that those skewed fractions become stacked fractions. Here's an example: Before running macro: After running macro: I can change these back by highlighting each fraction and then selecting "Change to Skewed Fraction", but it'd be great if there were a way to ensure the macro doesn't change the fraction. Any thoughts? |
Hello, thanks so much for pandoc-crossref. It's worked perfectly for me to achieve numbered equations and cross-references to them when compiling from md to docx (which was a need that led me to abandon LaTeX and begin writing in Markdown).
I was just wondering: is there any way to force equations to be right-justified within their respective cells when using the tableEqns feature?
Thanks!
The text was updated successfully, but these errors were encountered: