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

index refers to wrong page when indexing words outside of the mainmatter #1274

Closed
ttimbers opened this issue Oct 21, 2021 · 12 comments
Closed
Labels
tinytex related to LaTeX and tinytex support

Comments

@ttimbers
Copy link

I initially opened a thread about this in the RStudio Community forum, but after further investigation, I think this might be a bug.

When using bookdown to render to pdf following the instructions in Write a Book with bookdown and Publish with Chapman & Hall, we have found (in two separate projects) that items that are indexed in the frontmatter are given the wrong page number - they get pointed to a page of the list of figures, but not to the preface.

So, including something like this in index.Rmd (which comes before the /mainmatter command):

Basic familiarity with version control\index{version control} and ...

Gets a page number of "x" - which is one of the pages of the list of figures. I have looked in this bookdown repo and see the same thing happens with the demo book:

There is an Index entry in the front matter (index.Rmd) for Git Book on line 54 that looks like this:

... and imported the GitBook\index{GitBook} style ...

Then in the pdf the index entry for Git Book is "ix", which is a list of figure page:

Screen Shot 2021-10-20 at 8 02 25 PM

Screen Shot 2021-10-20 at 8 02 56 PM

@ttimbers
Copy link
Author

Just a gentle ping about this issue...

@cderv
Copy link
Collaborator

cderv commented Jan 17, 2022

Hi @ttimbers,

Thanks for the ping. That is not an easy one to investigate as it is tied to how latex work. in fact, \index feature is not part of bookdown - it is brought by LaTeX by adding

  \usepackage{makeidx}
  \makeindex

in preamble using header includes and

  \printindex

where to place the index, usually in after body includes.

I tested with bookdown-demo book and I can"t seem to reproduce this issue. I saw it on the bookdown book too and I wonder if this is not something related to the special class to use for Chapman and Hall: krantz.cls

Are you using this documentclass too ? It seems you do https://github.com/UBC-DSCI/introduction-to-datascience/blob/master/pdf/krantz.cls

I don't really know where to look in bookdown for this. I wonder if someone maintaining the krants class could help us see if this maybe be from the class processing or not 🤔

Did you encounter this issue with another documentclass ?

@yihui
Copy link
Member

yihui commented Jan 18, 2022

For problems related to krantz.cls, usually there is only one person who can help---Shashi Kumar <texhelp@taylorandfrancis.com> (Chapman & Hall's TeX help desk).

@ttimbers
Copy link
Author

Thanks @cderv and @yihui - I will reach out to Shashi!

@trevorcampbell
Copy link

trevorcampbell commented Jan 23, 2022

@cderv and @yihui -- @ttimbers and I worked a bit with Shashi and we found that:

  • if we manually compile bookdown.tex (output by bookdown) only once, then run makeindex, then compile again, the issue we noticed shows up -- the index entries in the preface / frontmatter don't point to the right pages
  • if we manually compile bookdown.tex twice, then run makeindex, then compile again, the index entries all look correct

So basically it looks like krantz.cls is fine and that it boils down to how many times the latex is being compiled before running makeindex.

Is this something that bookdown controls when it calls pandoc (maybe some config params that it passes in?), or is it a bug in pandoc where it isn't properly recognizing how many times it needs to compile, or something else?

@trevorcampbell
Copy link

trevorcampbell commented Jan 23, 2022

Ah, I think I may have found the issue -- it's in the tinytex repo

https://github.com/yihui/tinytex/blob/a339f67403637ff7f8d9ca062e359133b63554b0/R/latex.R#L226

run_engine() is only run once before making the index -- I think it may need to be run twice.

I'll test this out on our book, one moment...

@trevorcampbell
Copy link

Yup, that fixed it. I added a line after line 226 of latex.R in tinytex with an extra call to run_engine(), and our index entries look good now.

@yihui @cderv -- not sure if that's a reasonable fix or if there's something more clever to do, but at least we've nailed down the problem and a candidate fix. Please let us know how to proceed.

@cderv
Copy link
Collaborator

cderv commented Jan 24, 2022

Wow thanks a lot for the investigation !

Does makeindex requires 2 render before in general case ? Or is this specific to our .tex file ? I don't know enough LaTeX to know this. Sorry it makes no sense.

@yihui is this something you would look for a fix in tinytex or specific to bookdown ?

It seems that it could happens with any tex file that requires makeindex 🤔 I wonder if there is something in the log file that would help know than latexmk() needs to still run once more.

@trevorcampbell I believe that if you set option tinytex.latexmk.emulation to FALSE (not using tinytex emulation of latexmk() but using latexmk program directly) this will work ? Probably that latexmk knows what to do ?

@yihui
Copy link
Member

yihui commented Jan 24, 2022

@yihui is this something you would look for a fix in tinytex or specific to bookdown ?

We should fix it in tinytex.

@cderv cderv added the tinytex related to LaTeX and tinytex support label Jan 24, 2022
@trevorcampbell
Copy link

trevorcampbell commented Jan 24, 2022

Does makeindex requires 2 render before in general case

Yes, I believe so (it's similar to hyperlinks in the main text)

It seems that it could happens with any tex file that requires makeindex thinking I wonder if there is something in the log file that would help know than latexmk() needs to still run once more.

Looking at the code right after the run_engine() call I pointed out, it seems there is already an if statement to check whether an .idx file was created. You could just put a call to run_engine() at the start of the if scope.

  # some problems only trigger warnings but not errors, e.g.,
  # https://github.com/yihui/tinytex/issues/311 fix them and re-run engine
  if (install_packages && check_extra(logfile)) run_engine()

  # generate index
  if (file.exists(idx <- aux_files['idx'])) {
    idx_engine = getOption('tinytex.makeindex', 'makeindex')
    install_cmd(idx_engine)
    system2_quiet(idx_engine, c(getOption('tinytex.makeindex.args'), shQuote(idx)), error = {
      stop("Failed to build the index via ", idx_engine, call. = FALSE)
    })
  }

I believe that if you set option tinytex.latexmk.emulation to FALSE

@cderv how do I do this? I assume I have to add something to the index.Rmd file?

We should fix it in tinytex.

I'll leave it in your capable hands :)

@yihui
Copy link
Member

yihui commented Jan 24, 2022

I just pushed the fix. You can test the development version of tinytex via

remotes::install_github('yihui/tinytex')

Thanks!

clrpackages pushed a commit to clearlinux-pkgs/R-tinytex that referenced this issue Feb 17, 2022
…0.37

J.J. Allaire (1):
      add xpatch for quarto theorem rendering (#353)

Yihui Xie (8):
      start the next version
      move more settings into appveyor.yml
      update pandoc version
      deploy artifacts to Github directly
      not sure if an env var exported from the Ubuntu job works for the release description
      fix rstudio/bookdown#1274: run the LaTeX engine one more time before calling makeindex
      not sure why this choco command fails from time to time; see if appveyor-retry helps
      CRAN release v0.37
@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2022
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Dec 31, 2022
tinytex 0.43
  * Added the LaTeX package pdfcol to the TinyTeX bundle (#387).
  * Removed the internal use of xfun::isFALSE() (yihui/xfun#67).

tinytex 0.42
  * Querying CTAN might time out, which can cause failure in installing TinyTeX
    (thanks, Lillian Welsh, https://stackoverflow.com/q/73404800/559676).

  * When installing TinyTeX on macOS and the directory /usr/local/bin does not
    exist, users will be prompted to create it. Then if it is not writable,
    users will be prompted to make it writable via chown (a13ae48).

tinytex 0.41
  * TinyTeX no longer defines the TEXMFHOME variable (thanks, @vsheg, #377).

  * The internal function fc_cache() also runs on the TinyTeX root directory
    now (3d146ac).

tinytex 0.40
  * Added a bundle argument to tinytex::install_tinytex(), so that users can
    choose to install any TinyTeX bundle, e.g., TinyTeX-0 or TinyTeX-2.

tinytex 0.39

  * The tinytex and tinytex-releases repositories have been moved from @yihui's
    account to @rstudio, i.e., their addresses are https://github.com/rstudio/
    tinytex/ and https://github.com/rstudio/tinytex-releases/ now.

  * The full TeX Live has been pre-built as the TinyTeX-2 bundle in the daily
    release of TinyTeX: https://github.com/rstudio/tinytex-releases/releases/
    tag/daily To know how to install it, please see https://github.com/rstudio/
    tinytex-releases#installation.

  * If tinytex::install_tinytex() detects an existing LaTeX distribution in the
    system, it will ask if you want to continue the installation in an
    interactive R session. If this function is called in a non-interactive R
    session (e.g., via the Rscript command), it will throw an error in this
    case, unless the argument force = TRUE is used. This is to prevent an
    accidental installation of TinyTeX (which occurred on CRAN recently).
    Another way to prevent the installation is to set the environment variable
    TINYTEX_PREVENT_INSTALL=true.

  * On *nix, if the dir ~/.local/bin exists, it will be used as the bin path
    for TinyTeX, i.e., symlinks of TeX Live binaries will be created to this
    dir. If it does not exist, ~/bin/ will be used as usual (thanks, @salim-b,
    #365).

tinytex 0.38
  * Fixed #354: set the env var TEXLIVE_PREFER_OWN=1 before calling tlmgr() to
    use TeX Live's own curl instead of curl on PATH (thanks, @netique).

  * Fixed latex3/luaotfload#213: detect the lua-uni-algos package in case of
    error module 'lua-uni-normalize' not found (thanks, @dragonstyle).

  * Added the help page ?tinytex (thanks, @AmeliaMN, #361).

  * Use set -e and curl -f to fail immediately in the *nix installation script
    (thanks, @gaborcsardi, #356).

tinytex 0.37
  * Fixed rstudio/bookdown#1274: latexmk() should run the LaTeX engine one more
    time before calling makeindex (thanks, @trevorcampbell @ttimbers).

tinytex 0.36
  * Fixed the failure to detect the hyphen-french package from the LaTeX log:
    https://stackoverflow.com/q/69887190/559676

  * xfun::session_info('tinytex') can report the TeX Live (TinyTeX) version
    now.

  * Improved the way tinytex::tlmgr_repo() normalizes the repo URL (#346).

tinytex 0.35
  * install_tinytex() will automatically switch to using https://github.com/
    yihui/tinytex-releases/releases/tag/daily to install the daily version of
    TinyTeX if accessing https://yihui.org fails (#332).

  * install-bin-unix.sh and install-bin-windows.bat now install TinyTeX from
    https://github.com/yihui/tinytex-releases/releases/tag/daily instead of
    https://yihui.org/tinytex/TinyTeX.* (#270).

  * Fixed #322: automatically install hyphen-* packages in case of polyglossia
    warnings.

  * Run tlmgr conf texmf max_print_line 10000 to prevent LaTeX from wrapping
    log lines (#322 (comment)). If you do not like this configuration, you may
    run tlmgr conf texmf --delete max_print_line to delete it.

tinytex 0.34
  * The --data argument in tl_sizes() is properly quoted now to make it work on
    Windows (thanks, @IndrajeetPatil #329, @cderv #330).
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 18, 2023
tinytex 0.43
  * Added the LaTeX package pdfcol to the TinyTeX bundle (#387).
  * Removed the internal use of xfun::isFALSE() (yihui/xfun#67).

tinytex 0.42
  * Querying CTAN might time out, which can cause failure in installing TinyTeX
    (thanks, Lillian Welsh, https://stackoverflow.com/q/73404800/559676).

  * When installing TinyTeX on macOS and the directory /usr/local/bin does not
    exist, users will be prompted to create it. Then if it is not writable,
    users will be prompted to make it writable via chown (a13ae48).

tinytex 0.41
  * TinyTeX no longer defines the TEXMFHOME variable (thanks, @vsheg, #377).

  * The internal function fc_cache() also runs on the TinyTeX root directory
    now (3d146ac).

tinytex 0.40
  * Added a bundle argument to tinytex::install_tinytex(), so that users can
    choose to install any TinyTeX bundle, e.g., TinyTeX-0 or TinyTeX-2.

tinytex 0.39

  * The tinytex and tinytex-releases repositories have been moved from @yihui's
    account to @rstudio, i.e., their addresses are https://github.com/rstudio/
    tinytex/ and https://github.com/rstudio/tinytex-releases/ now.

  * The full TeX Live has been pre-built as the TinyTeX-2 bundle in the daily
    release of TinyTeX: https://github.com/rstudio/tinytex-releases/releases/
    tag/daily To know how to install it, please see https://github.com/rstudio/
    tinytex-releases#installation.

  * If tinytex::install_tinytex() detects an existing LaTeX distribution in the
    system, it will ask if you want to continue the installation in an
    interactive R session. If this function is called in a non-interactive R
    session (e.g., via the Rscript command), it will throw an error in this
    case, unless the argument force = TRUE is used. This is to prevent an
    accidental installation of TinyTeX (which occurred on CRAN recently).
    Another way to prevent the installation is to set the environment variable
    TINYTEX_PREVENT_INSTALL=true.

  * On *nix, if the dir ~/.local/bin exists, it will be used as the bin path
    for TinyTeX, i.e., symlinks of TeX Live binaries will be created to this
    dir. If it does not exist, ~/bin/ will be used as usual (thanks, @salim-b,
    #365).

tinytex 0.38
  * Fixed #354: set the env var TEXLIVE_PREFER_OWN=1 before calling tlmgr() to
    use TeX Live's own curl instead of curl on PATH (thanks, @netique).

  * Fixed latex3/luaotfload#213: detect the lua-uni-algos package in case of
    error module 'lua-uni-normalize' not found (thanks, @dragonstyle).

  * Added the help page ?tinytex (thanks, @AmeliaMN, #361).

  * Use set -e and curl -f to fail immediately in the *nix installation script
    (thanks, @gaborcsardi, #356).

tinytex 0.37
  * Fixed rstudio/bookdown#1274: latexmk() should run the LaTeX engine one more
    time before calling makeindex (thanks, @trevorcampbell @ttimbers).

tinytex 0.36
  * Fixed the failure to detect the hyphen-french package from the LaTeX log:
    https://stackoverflow.com/q/69887190/559676

  * xfun::session_info('tinytex') can report the TeX Live (TinyTeX) version
    now.

  * Improved the way tinytex::tlmgr_repo() normalizes the repo URL (#346).

tinytex 0.35
  * install_tinytex() will automatically switch to using https://github.com/
    yihui/tinytex-releases/releases/tag/daily to install the daily version of
    TinyTeX if accessing https://yihui.org fails (#332).

  * install-bin-unix.sh and install-bin-windows.bat now install TinyTeX from
    https://github.com/yihui/tinytex-releases/releases/tag/daily instead of
    https://yihui.org/tinytex/TinyTeX.* (#270).

  * Fixed #322: automatically install hyphen-* packages in case of polyglossia
    warnings.

  * Run tlmgr conf texmf max_print_line 10000 to prevent LaTeX from wrapping
    log lines (#322 (comment)). If you do not like this configuration, you may
    run tlmgr conf texmf --delete max_print_line to delete it.

tinytex 0.34
  * The --data argument in tl_sizes() is properly quoted now to make it work on
    Windows (thanks, @IndrajeetPatil #329, @cderv #330).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tinytex related to LaTeX and tinytex support
Projects
Archived in project
Development

No branches or pull requests

4 participants