thesisdown icon indicating copy to clipboard operation
thesisdown copied to clipboard

LaTeX Error: Lonely \item--perhaps a missing list environment

Open GregForkutza opened this issue 10 months ago • 17 comments

Describe the bug I am using the cloned repo as is and no changes are made. I try to knit index. Rmd. The pdf does not compile. I get the following Error:

! LaTeX Error: Lonely \item--perhaps a missing list environment. Error: LaTeX failed to compile thesis.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See thesis.log for more info. Execution halted

There is further related behaviour I cannot explain.

If I remove any of the citations using @ from 03-chap3.Rmd and lines 34-38 from 99-references.Rmd

nocite: | @angel2000, @angel2001, @angel2002a ...

then the pdf compiles directly from index.Rmd.

However If I leave the above lines in and knit Index.Rmd and then compile the thesis.tex file directly it produces a thesis.pdf file that contains the in text citation and the references list is filled, both correctly formatted. However Figure 3.2 now is missing its content but its caption is present.

Therefore there is some bug related to using in text citations.

Here is the the typical error from any citation from the thesis.log from trying to compile thesis.tex

! LaTeX Error: Lonely \item--perhaps a missing list environment. See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ...
l.917 \bibitem[\citeproctext]{ref-angel2000}
Try typing to proceed. If that doesn't work, type X to quit. Underfull \hbox (badness 10000) detected at line 917 [][] [] ! Undefined control sequence. ...\bibcite {ref-angel2000}{\citeproctext } l.917 \bibitem[\citeproctext]{ref-angel2000}
The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., \hobx'), type I' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.

To Reproduce Clone the repo as is and knit index.Rmd Expected behavior To be able to handle in text citations using the @ref syntax.

Desktop (please complete the following information):

  • OS: macOS Sonoma 14.1

Additional context Originally I was trying to get this work on the macdown rep for Mcmaster University and had the exact same problem.

GregForkutza avatar Apr 01 '24 18:04 GregForkutza

Hi there. Thanks for flagging. Can you also include your results of running sessionInfo() or something similar in R, so I can identify your versions of packages?

ismayc avatar Apr 01 '24 19:04 ismayc

sessionInfo() R version 4.3.2 (2023-10-31) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS Sonoma 14.4.1

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Toronto tzcode source: internal

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] remotes_2.5.0

loaded via a namespace (and not attached): [1] desc_1.4.3 digest_0.6.35 R6_2.5.1
[4] bookdown_0.38.1 thesisdown_0.2.0.9000 fastmap_1.1.1
[7] xfun_0.43 knitr_1.45 htmltools_0.5.8
[10] rmarkdown_2.26 ps_1.7.6 cli_3.6.2
[13] processx_3.8.4 callr_3.7.6 compiler_4.3.2
[16] rprojroot_2.0.4 here_1.0.1 rstudioapi_0.16.0
[19] tools_4.3.2 pkgbuild_1.4.4 curl_5.2.1
[22] evaluate_0.23 yaml_2.3.8 rlang_1.1.3

GregForkutza avatar Apr 01 '24 19:04 GregForkutza

Thanks. I'll try to see what's up.

ismayc avatar Apr 01 '24 19:04 ismayc

Can you clarify what you mean by "clone the repo"? It seems like LaTeX isn't synced up appropriately.

ismayc avatar Apr 01 '24 20:04 ismayc

I misspoke. I did clone a local copy of the repo to try editing source files (for debugging). But what i meant to say was that I first installed thesisdown and then created a new thesisdown project, from which i made no changes and only tried to knit index.Rmd.

You mention LaTex isnt synced up? What do you mean by that?

If I try to run say tinytex::tlmgr_install("babel-portuges")

Then I get this

tlmgr update --all --self tlmgr install babel-portuges tlmgr: Remote database (revision 70801 of the texlive-scripts package) seems to be older than the local installation (rev 70821 of texlive-scripts); please use a different mirror and/or wait a day or two. I don't know if that is relevant or not.

GregForkutza avatar Apr 01 '24 20:04 GregForkutza

I’m not seeing tinytex listed in your sessionInfo() output which seems strange and your \item error also is a LaTeX package error I believe. Maybe try to start fresh again at the top of the README for instructions?

I just did a fresh install and I’m not seeing any errors in building the PDF.

ismayc avatar Apr 01 '24 20:04 ismayc

I’m not sure about the error you are getting from tinytex::tlmgr_install("babel-portuges") either. That’s not a necessary package for things to build, but an example of how to add another LaTeX package.

ismayc avatar Apr 01 '24 20:04 ismayc

Thats weird, I just ran sessioninfo() again and am seeing tinytex.

I did as you said, and did a fresh install and its the same error. I also had another person, on a linux machine, do a fresh install and try to knit index.Rmd and they also had the exact same error as myself with identical thesis.log file.

GregForkutza avatar Apr 01 '24 21:04 GregForkutza

Darn. I’m really not sure since I can’t replicate on my Mac. I guess you could try a bookdown example instead to see if that gives the game kind of error? https://github.com/rstudio/bookdown-demo

ismayc avatar Apr 01 '24 21:04 ismayc

That example worked fine. No Issues. Would you possibly share your sessioninfo? Maybe there is something I am missing?

GregForkutza avatar Apr 01 '24 21:04 GregForkutza

The only major difference I see on initial look is that I'm using an older version of R on this machine:

R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 14.4.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_4.2.2        bookdown_0.38.1       fastmap_1.1.1        
 [4] cli_3.6.2             htmltools_0.5.7       tools_4.2.2          
 [7] rstudioapi_0.15.0     yaml_2.3.8            tinytex_0.50         
[10] rmarkdown_2.26        knitr_1.45            xfun_0.42            
[13] digest_0.6.34         thesisdown_0.2.0.9000 renv_1.0.5           
[16] rlang_1.1.3           evaluate_0.23  

ismayc avatar Apr 01 '24 21:04 ismayc

I used another 2021 M1 macbook and downloaded R, Rstudio and MacTex. Then followed the instructions on the readme and it worked fine. It has no issue.

It is possible this is caused by some conflicting LateX configuration on mine. I tried installing MacTex again and it had no effect. The only option I can see it to backup my computer and install everything again from a factory reset.

GregForkutza avatar Apr 02 '24 02:04 GregForkutza

Strange! Best of luck. LaTeX can be pretty unruly at times.

ismayc avatar Apr 02 '24 15:04 ismayc

I found the solution here: https://github.com/Zettlr/Zettlr/issues/4879

Specifically i made the following replacement in template.tex

I replaced lines 119-147 with

% definitions for citeproc citations
\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
\begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
% allow citations to break across lines
\let\@cite@ofmt\@firstofone
% avoid brackets around text for \cite:
\def\@biblabel#1{}
\def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
{\begin{list}{}{%
	\setlength{\itemindent}{0pt}
	\setlength{\leftmargin}{0pt}
	\setlength{\parsep}{0pt}
	% turn on hanging indent if param 1 is 1
	\ifodd #1
	\setlength{\leftmargin}{\cslhangindent}
	\setlength{\itemindent}{-1\cslhangindent}
	\fi
	% set entry spacing
	\setlength{\itemsep}{#2\baselineskip}}}
{\end{list}}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
$endif$ 

Id be very curious if you can confirm what might have been going on. But the best I can tell is that the /citeproctext command was not being "found" and so this fixes it by making those definitions in the template?

GregForkutza avatar Apr 03 '24 18:04 GregForkutza

Unfortunately, I'm not great at debugging LaTeX anymore these days. I'll keep this open to see if the template needs updating when I get a chance. Thanks for finding this!

ismayc avatar Apr 03 '24 18:04 ismayc

Got the same error on Windows. Indeed the solution in https://github.com/ismayc/thesisdown/issues/207#issuecomment-2035288739 indeed solved it+

> sessionInfo()
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_United Kingdom.utf8 
[2] LC_CTYPE=English_United Kingdom.utf8   
[3] LC_MONETARY=English_United Kingdom.utf8
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.utf8    

time zone: Europe/London
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached):
 [1] compiler_4.4.0        bookdown_0.39        
 [3] fastmap_1.1.1         cli_3.6.2            
 [5] htmltools_0.5.8.1     tools_4.4.0          
 [7] rstudioapi_0.16.0     yaml_2.3.8           
 [9] remotes_2.5.0         rmarkdown_2.27       
[11] knitr_1.47            xfun_0.45            
[13] digest_0.6.35         thesisdown_0.2.0.9000
[15] rlang_1.1.3           evaluate_0.24.0  

andreifoldes avatar Jun 18 '24 23:06 andreifoldes

Hey, I just wanted to add that I ran into the same issue, and the solution in https://github.com/ismayc/thesisdown/issues/207#issuecomment-2035288739 also worked for me.

Wanting to use biblatex, I went down a little rabbit hole and found a solution that someone might find helpful, so I am sharing it here: As a disclaimer, I am not super experienced in (Lua)LaTeX, so I asked ChatGPT for some help here and there.

My goal was to be able to use citeproc/biblatex interchangeably. Therefore, I added a biblatex parameter in the index.Rmd YAML:

params:
  'Install needed packages for {thesisdown}': false
  biblatex: false

I (read: ChatGPT) then created a lua filter to replace [@reference] with \cite{reference}, in the document. This means that both [@reference] and \cite{reference} will work with biblatex, but only the former will work with citeproc (if the filter is disabled). This also works with [@ref1;@ref2;...] notation.

cite_filter.lua:

function Cite(el)
  -- Collect all citation keys into a single table
  local citations = {}
  for _, citation in ipairs(el.citations) do
    table.insert(citations, citation.id)
  end
  
  -- Concatenate all citation keys with commas
  local citation_str = table.concat(citations, ",")
  
  -- Return a single RawInline element containing the LaTeX \cite{...} command
  return pandoc.RawInline("latex", "\\cite{" .. citation_str .. "}")
end

In the index.Rmd YAML, replace the output with:

output:
  thesisdown::thesis_pdf:
    highlight: default
    latex_engine: lualatex
    pandoc_args:
      - --lua-filter=cite_filter.lua

As a note, to use citeproc from here on, you would need to comment out the lua-filter pandoc argument and set biblatex: false.

In template.tex, replace the entire $if(csl-refs)$ section with:

$if(params.biblatex)$
\usepackage[backend=biber,
    style=authoryear,
    bibstyle=numeric
    % other style options...
    ]{biblatex}

\renewcommand*{\bibfont}{\small}
\renewcommand*{\finalnamedelim}{\addcomma\space}
% 
\addbibresource{$bibliography$}

\newcommand{\addbib}{
\phantomsection
\addcontentsline{toc}{chapter}{Bibliography}
\renewcommand\bibname{Bibliography}
\printbibliography
}

$else$
% definitions for citeproc citations
\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
\begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
% allow citations to break across lines
\let\@cite@ofmt\@firstofone
% avoid brackets around text for \cite:
\def\@biblabel#1{}
\def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
{\begin{list}{}{%
	\setlength{\itemindent}{0pt}
	\setlength{\leftmargin}{0pt}
	\setlength{\parsep}{0pt}
	% turn on hanging indent if param 1 is 1
	\ifodd #1
	\setlength{\leftmargin}{\cslhangindent}
	\setlength{\itemindent}{-1\cslhangindent}
	\fi
	% set entry spacing
	\setlength{\itemsep}{#2\baselineskip}}}
{\end{list}}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{\strut#1\strut}}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}

\newcommand{\addbib}{
\chapter*{Bibliography}
\addcontentsline{toc}{chapter}{Bibliography}
}
$endif$

The 99_references.Rmd becomes:

\backmatter
\addbib

# Add citeproc div box
```{r citeprocrefs, echo=FALSE, results='asis'}
if (!params$biblatex) {
  cat('
  \\setlength{\\parindent}{-0.20in}
  \\setlength{\\leftskip}{0.20in}
  \\setlength{\\parskip}{8pt}
  <div id="refs"></div>')
}
```# end

where \addbib is defined in the section above

To compile with biber, I created this R script (you may need to change the biber location):

bookdown::render_book("index.Rmd")
system("mv _book/thesis.tex .")
system("lualatex thesis")
system("/opt/homebrew/bin/biber thesis")
system("lualatex thesis")
system("lualatex thesis")
system("mv thesis.pdf _book/")
system("mv thesis.tex _book/")
system("ls thesis.* | grep -v 'thesis.bbl' | xargs rm")

The script retains the thesis.bbl file so that you can knit index.Rmd normally, given that you don't add new references (you can reuse already added ones still).

I hope this is helpful to anyone, and if you have any suggestions for improvement, I am happy to learn :)

EDIT: Overlooked the <div id="refs"></div> in the refs. It is now added with an R chunk.

shdam avatar Aug 30 '24 09:08 shdam