Skip to content
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

Figure number reset for figures in different headings #76

Closed
pwolfram opened this issue Jan 29, 2020 · 12 comments
Closed

Figure number reset for figures in different headings #76

pwolfram opened this issue Jan 29, 2020 · 12 comments
Labels

Comments

@pwolfram
Copy link

Figures numbers are reset under different headings, e.g., for a file tester.md,

# head 1                             

![Fig1](){#fig:fig1}

blah blah Fig @fig:fig1.

![Fig2](){#fig:fig2}

blah blah Fig @fig:fig2.

# head 2

![Fig3](){#fig:fig3}

blah blah Fig @fig:fig3.

built by pandoc -o tester.docx -f markdown -t docx tester.md --filter=pandoc-xnos; open tester.docx
produces output like
image

Is this expected behavior?

Version info:

pandoc --version
pandoc 2.2.3.2
Compiled with pandoc-types 1.17.5.1, texmath 0.11.0.1, skylighting 0.7.2
Default user data directory: /Users/pwolfram/.pandoc
Copyright (C) 2006-2018 John MacFarlane
Web:  http://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.

pip install  pandoc-xnos
Requirement already satisfied: pandoc-xnos in /Users/pwolfram/miniconda3/lib/python3.7/site-packages (2.3.0)
Requirement already satisfied: psutil<6,>=4.1.0 in /Users/pwolfram/miniconda3/lib/python3.7/site-packages (from pandoc-xnos) (5.6.3)
Requirement already satisfied: pandocfilters<2,>=1.4.2 in /Users/pwolfram/miniconda3/lib/python3.7/site-packages (from pandoc-xnos) (1.4.2)
@p3palazzo
Copy link

Happens only in the docx/odt writers for me. PDF is correctly numbered.

@pwolfram
Copy link
Author

Thanks @p3palazzo, I also didn't check latex or html compatibility either because my use case is docx for this application.

Minimally, I would expect design behavior to be consistent between docx/odt/pdf/latex/html/etc unless I've missed something in terms of design criteria.

Advice on how to dig in is appreciated. My work-around will be to just hard code figure numbers for now.

@jschlatow
Copy link

@pwolfram @p3palazzo The reason why PDF is correctly numbered is that LaTeX/pdf does the numbering itself whereas for other output formats, pandoc-fignos must do hard-code the figure numbers.

I had a quick look at the code and believe the reason for this is that the figure number is reset in every section irrespective of whether fignos-number-by-section is set or not. A patch for this might be:

diff --git a/pandoc_fignos.py b/pandoc_fignos.py
index da1039a..9d21696 100644
--- a/pandoc_fignos.py
+++ b/pandoc_fignos.py
@@ -83,7 +83,7 @@ warninglevel = 2        # 0 - no warnings; 1 - some warnings; 2 - all warnings
 
 # Processing state variables
 cursec = None  # Current section
-Ntargets = 0   # Number of targets in current section (or document)
+Ntargets = 1   # Number of targets in current section (or document)
 targets = {}   # Global targets tracker
 
 # Processing flags
@@ -172,7 +172,8 @@ def _process_figure(key, value, fmt):
     # Update the current section number
     if attrs['secno'] != cursec:  # The section number changed
         cursec = attrs['secno']   # Update the global section tracker
-        Ntargets = 1              # Resets the global target counter
+        if numbersections:
+            Ntargets = 1              # Resets the global target counter
 
     # Pandoc's --number-sections supports section numbering latex/pdf, html,
     # epub, and docx

By the way, this will also affect the other pandoc-*nos filters.

@p3palazzo
Copy link

Thank you @ValiValpas. The patch works in all common use cases (PDF, DOCX, ODT, HTML). When setting fignos-number-by-section: True in DOCX output, the sections themselves are not numbered (a problem with Pandoc's section numbering? using pandoc's --number-sections, of course), but the figures are correctly numbered as 1.1, 1.2, 2.1, etc.

@pwolfram
Copy link
Author

What is the culture here for PRs/patches? Don't know what my responsibility as a contributor is in this venue but can help on this later next week.

Thanks everyone for digging in and for the solution!

@uthpalaherath
Copy link

This happens when converting markdown to HTML. Works fine for PDF.

@p3palazzo
Copy link

What is the culture here for PRs/patches? Don't know what my responsibility as a contributor is in this venue but can help on this later next week.

@ValiValpas should be the one making the pull request because he came up with the solution, otherwise we'd be taking credit for his work.

@Dabsen
Copy link

Dabsen commented Mar 4, 2020

Thanks! But what is the status of this fix? @ValiValpas, did you actually make the pull request? I can't see it.

@jschlatow
Copy link

@Dabsen, I referenced this issue in my commit so that my commit is shown in this issue. A pull request is not necessary, it would just create another issue that needs to be referenced and synced with this one.

@debug-ito
Copy link

I'm having this issue. A workaround (by the user) is to add "secno=1" attribute to every figures. E.g.

![Figure One](fig_one.png){#fig:one secno=1}

@tomduck
Copy link
Owner

tomduck commented Jul 30, 2020

Thank you for this report and discussion, which were helpful. Sorry for the long wait.

The problem is now fixed in the nextrelease branch. If problems persist beyond the next release, please re-open this Issue.

Tom

@tomduck tomduck closed this as completed Jul 30, 2020
@tomduck tomduck added the bug label Jul 30, 2020
@tomduck
Copy link
Owner

tomduck commented Jul 30, 2020

pandoc-fignos 2.3.0 is now released. --Tom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants