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

cross referencing latex tables in elseveier quarto template #17

Open
jpatteet opened this issue Jul 27, 2023 · 10 comments
Open

cross referencing latex tables in elseveier quarto template #17

jpatteet opened this issue Jul 27, 2023 · 10 comments

Comments

@jpatteet
Copy link

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 ?

@dragonstyle
Copy link
Collaborator

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?

@jpatteet
Copy link
Author

jpatteet commented Jul 28, 2023

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 ?

@dragonstyle
Copy link
Collaborator

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

@jpatteet
Copy link
Author

$ 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)

@dragonstyle
Copy link
Collaborator

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.

@jpatteet
Copy link
Author

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.

@dragonstyle
Copy link
Collaborator

This is working fine for me:

---
title: "TITLE"
author:
  - name: Myname
    email: [email protected]
    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: [email protected]
    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}
```

@jpatteet
Copy link
Author

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.

@dragonstyle
Copy link
Collaborator

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....

@jpatteet
Copy link
Author

jpatteet commented Aug 4, 2023

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

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

No branches or pull requests

2 participants