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

VimtexCountWords inaccurate on range (apa7 document class) #2935

Open
A-Daneel opened this issue Apr 22, 2024 · 5 comments
Open

VimtexCountWords inaccurate on range (apa7 document class) #2935

A-Daneel opened this issue Apr 22, 2024 · 5 comments
Labels

Comments

@A-Daneel
Copy link

Description

as the title states, when using the apa7 document class VimtexCountWords gives an inaccurate word count when done over a range. From my (minimal) testing, it seems to include the title.

The odd thing is, if you run it over the entire document it seems to give the correct word count. Not sure how I'd go about debugging it further (and if it's an issue that belongs here or on the apa7 package).

Would love to take a shot at it, but I'll need some pointers to get started :)

Steps to reproduce

minimal latex file

\documentclass[stu]{apa7}

\title{A title}
\shorttitle{A short title}
\author{An author}

\begin{document}

\thispagestyle{empty}
\maketitle

Some text.

Some more text.

\end{document}

if you highlight the "some text." line, and run :'<,'>VimtexCountWords it'll say it's 4 long. ("some text." + "A title")

if you highlight the "some more text" line, and run :'<,'>VimtexCountWords it'll say it's 5 long. ("some more text." + "A title")

If you highlight nothing and run :VimtexCountWords it'll give you the correct word count of 7.

Expected behavior

When following the steps, I'd expect to only get the word count of the selection.

Actual behavior

Currently I get the selection and the title.

Do you use a latexmkrc file?

no

VimtexInfo

System info:
  OS: Ubuntu 22.04.3 LTS
  Vim version: NVIM v0.10.0-dev-2943+gb0f922817
  Has clientserver: true
  Servername: /run/user/1000/nvim.318158.0

VimTeX project: countWords
  base: countWords.tex
  root: /home/daneel/vimtex
  tex: /home/daneel/vimtex/countWords.tex
  main parser: current file verified
  document class: apa7
  packages: atbegshi atbegshi-ltx atveryend atveryend-ltx auxhook bigintcalc bitset bm booktabs calc caption caption3 endfloat etoolbox fancyhdr fontenc geometry gettitlestring graphics graphicx hycolor hyperref iftex ifvtex infwarerr intcalc keyval kvdefinekeys kvoptions kvsetkeys letltxmacro lmodern ltxcmds nameref pdfescape pdftexcmds pgf pgfcomp-version-0-65 pgfcomp-version-1-18 pgfcore pgffor pgfkeys pgfmath pgfrcs pgfsys refcount rerunfilecheck scalerel stringenc threeparttable tikz trig uniquecounter url xcolor
  compiler: latexmk
    engine: -xelatex
    options:
      -shell-escape
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Zathura
    xwin id: 0
  qf method: LaTeX logfile
@A-Daneel A-Daneel added the bug label Apr 22, 2024
@lervag
Copy link
Owner

lervag commented Apr 22, 2024

as the title states, when using the apa7 document class VimtexCountWords gives an inaccurate word count when done over a range. From my (minimal) testing, it seems to include the title.

That's fascinating. The :'<,'>VimtexCountWords is actually slightly hacky. Notice the implementation:

if l:range == [1, line('$')]
let l:file = b:vimtex
else
let l:file = vimtex#parser#selection_to_texfile({'range': l:range})
endif
let l:cmd = 'texcount -nosub -sum '
\ . (get(l:opts, 'count_letters') ? '-letter ' : '')
\ . (get(l:opts, 'detailed') ? '-inc ' : '-q -1 -merge ')
\ . g:vimtex_texcount_custom_arg . ' '
\ . vimtex#util#shellescape(l:file.base)
let l:lines = vimtex#jobs#capture(l:cmd, {'cwd': l:file.root})

When you use a selection, VimTeX will create a temporary file that keeps the current preamble. Notice that you will get 7 words even if you remove the \maketitle command. Thus, it seems the apa7 class will include the title even if you don't use that command?

@A-Daneel
Copy link
Author

Thanks for responding, my viml isn't that great and I wondered how texcount worked on a range.

Am I correct in assuming that it creates a temporary file with the same class as the primary file (apa7 in this case)?

If so, the temp file should look like this when Some text. is highlighted, right?

\documentclass[stu]{apa7}

\title{A title}
\shorttitle{A short title}
\author{An author}

\begin{document}

Some text.

\end{document}

which would render the following
afbeelding

This to me makes it less understandable, since the minimal version renders the shorttitle but when asking the count it adds the title. (notice that if you keep the title empty \title{} it will give you the correct word count, but the rendered image does not change)

@lervag
Copy link
Owner

lervag commented Apr 24, 2024

Yes, that's precisely what happens. Notice that the word count of this temp file is the count that texcount provides, so if it is wrong, then that's not a bug in VimTeX, but a bug in texcount.

@A-Daneel
Copy link
Author

Thanks for walking me through the VimTeX part of it. I'll open an issue on the texcount git, it sadly does look pretty stale (last commit is 4 years ago and it has 3 open issues and 1 pr). Or would you be open to including a workaround?

From some quick testing the behavior also seems to appear if you change the class to minimal. If it is a bug with \title regardless of the class it could be something that hinder more people. (though, I don't really see a straight forward solution)

@lervag
Copy link
Owner

lervag commented Apr 24, 2024

Thanks for walking me through the VimTeX part of it. I'll open an issue on the texcount git, it sadly does look pretty stale (last commit is 4 years ago and it has 3 open issues and 1 pr).

I think that is a good idea, even if it is apparently state. However, the maintainer did reply to the existing issues, so he might still suddenly be motivated to fix things?

Or would you be open to including a workaround?

Well, it seems somewhat fragile to add workarounds for texcount to VimTeX. I would be much more interested if there happen to be valid alternative tooling that we could hook into.

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

2 participants