quarto-journals/elsevier

cross referencing latex tables in elseveier quarto template

Opened this issue · 10 comments

I would like to cros reference a latex table in my text.
Originally I was not using the elsevier template and the solution I used was adding the following packages.

---
format: pdf
header-includes:
  - \usepackage{hyperref}
  - \usepackage[capitalise,noabbrev]{cleveref}
---

I can then cross ref a latex table using \cref{Variabilities}

(because I have \label{Variabilities} in my table)

I tried using the same idea in the elsevier template

---
format:
  elsevier-pdf:
    keep-tex: true
    include-in-header: |
      \usepackage{multirow}
      \usepackage{hyperref}
      \usepackage[capitalise,noabbrev]{cleveref}
    journal:
      name: Forensic Science International
      formatting: preprint
      model: 3p
      cite-style: authoryear
---

But I always get the same error:

updating tlmgr
updating existing packages
compilation failed- error
Undefined control sequence.
l.887 information (W or B as explained in \cref{Variabilities})

Any idea how I could work around this issue ?

I'm not seeing an error with PDF rendering when I do use the following:

format:
  elsevier-pdf:
    keep-tex: true
    include-in-header:
      text: |
        \usepackage{multirow}
        \usepackage{hyperref}
        \usepackage[capitalise,noabbrev]{cleveref}
    journal:
      name: Forensic Science International
      formatting: preprint
      model: 3p
      cite-style: authoryear

When I use you example which includes include-in-header, I do see an error in Quarto output (though rendering appears to continue, which seems bad). include-in-header when used directly is expecting a file path whose contents will be placed verbatim in the header. The text subkey lets Quarto know that this is text (not a file)...

Does that fix it for you as well?

creflatexFSI.txt

When I add text subkey I get the same error.
I made a quick example with the exact table I want to cite in my document.
Do you get the same result as me with this example ?

It does work fine - are you using the command --to elsevier-pdf when rendering / previewing? That is required in order to target the format (this got me in my testing when I realized that the usepackage statements were not appearing in my generated LaTeX) :

quarto render test.qmd --to elsevier-pdf

Screenshot 2023-07-28 at 8 14 36 AM

$ quarto render TestcrefFSI.qmd --to elsevier-pdf
pandoc
  to: latex
  output-file: TestcrefFSI.tex
  standalone: true
  shift-heading-level-by: -1
  pdf-engine: xelatex
  variables:
    graphics: true
    tables: true
  default-image-extension: pdf
  cite-method: natbib
  number-sections: true

metadata
  block-headings: true
  date-format: full
  documentclass: elsarticle

running xelatex - 1
  This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

updating tlmgr

updating existing packages

compilation failed- error
Undefined control sequence.
l.171 information (W or B as explained in \cref
                                               {Variabilities}).

see TestcrefFSI.log for more information.

I was rendering with the render button but with the command I have the same error.

Here is the .log file:
TestcrefFSI.log

Also, when I use \ref{Variabilities} instead of \cref{Variabilities},

I get the following error:

updating tlmgr

updating existing packages

compilation failed- error
Undefined control sequence.
\@sharp ->\multirow
                    {2}{*}{\textbf {Zone}}
l.181 ...n{1}{|c|}{\multirow{2}{*}{\textbf{Zone}}}
                                                   & \textit{Same}      & \m...

see TestcrefFSI.log for more information.

Could it be that there is something wrong with where my packages are ? (knowing that it works fine when I am not using the elsevier template)

That appears to be a problem with your table formatting. I removed some white space from the table definition to make mine work- but you can confirm this by simply leaving the other table skeleton with label and caption and omitting the table itself. If this renders it is likely just a problem with the way the table itself is defined.

Removing the table itself removes the multirow error.
Do you have your version with removed white spaces ?

This does not resolve the \cref error but I will work with using ref only.

This is working fine for me:

---
title: "TITLE"
author:
  - name: Myname
    email: Myname@unil.ch
    affiliations: 
        - id: JPA-ESC
          name: School of Criminal Justice
          department: Faculty of Law, Criminal Justice and Public Administration
          address: University of Lausanne
          city: Switzerland
          state: Switzerland
          postal-code: 1015
          attributes:
    corresponding: true
  - name: name2
    email: name2@unil.ch
    affiliations: 
        - id: CC-ESC
          name: School of Criminal Justice
          department: Faculty of Law, Criminal Justice and Public Administration
          address: University of Lausanne
          city: Switzerland
          state: Switzerland
          postal-code: 1015
 
abstract: |
  BLABLABALA.
  
keywords: 
  - Toolmarks
  - Review

  
date: last-modified
bibliography: Biblio.bib
format:
  elsevier-pdf:
    keep-tex: true
    include-in-header:
      text: |
        \usepackage{multirow}
        \usepackage{hyperref}
        \usepackage[capitalise,noabbrev]{cleveref}
    journal:
      name: Forensic Science International
      formatting: preprint
      model: 3p
      cite-style: authoryear
---

This is a test:

A dataset is created with comparisons from both classes. They are all stored in a dataframe (a matrix of numerical and non-numerical data) which has information for each comparison about the different scores that were calculated, the lag between the two profiles, and the class information (W or B as explained in \cref{Variabilities}).

```{=latex}
\begin{table}[]
\caption{Summary of the different variabilities when comparing marks from same or different tools and zones}
\label{Variabilities}
\begin{center}
\begin{tabular}{ll|cc|}
\cline{3-4}
&                    & \multicolumn{2}{c|}{\textbf{Tool}}                                           \\ \cline{3-4} 
&                    & \multicolumn{1}{l|}{\textit{Same}} & \multicolumn{1}{l|}{\textit{Different}} \\ \hline
\multicolumn{1}{|c|}{\multirow{2}{*}{\textbf{Zone}}} & \textit{Same}      & \multicolumn{1}{c|}{W}             & B                                       \\ \cline{2-4} 
\multicolumn{1}{|c|}{}                               & \textit{Different} & \multicolumn{1}{c|}{B}             & B                                       \\ \hline
\end{tabular}
\end{center}
\end{table}
```

Thanks! works fine for me as well.

Any idea what can cause the run xelatex all the way down to the 10th iteration ? on my actual qmd (not the test).

I can't share it unfortunately, it calls for functions, .Rda, and JPG files.

I'm honestly not sure- there isn't a specific thing that causes this. It could be:

  • There is some layout that isn't completely successfully and we are detecting that and running another LaTeX compile to try to resolve that (unlikely but possible).
  • There is a bug where we're getting fooled onto re-rerunning the compilation even though it isn't necessary (we inspect the tex log to try to figure out whether another compilation is needed). (likely)

If you could enable keep-tex and share the tex log I might be able to determine if / what bug exists...

You can use latex-max-runs and latex-min-runs to control this manually if you can determine a specific number of runs that is required to successfully compile and typeset the PDF....

@dragonstyle I sent you an email with the .tex file as the content is not yet published.