ismayc / thesisdown

An updated R Markdown thesis template using the bookdown package
Other
804 stars 357 forks source link

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

Open GregForkutza opened 3 months ago

GregForkutza commented 3 months ago

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

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

ismayc commented 3 months ago

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?

GregForkutza commented 3 months ago

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

ismayc commented 3 months ago

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

ismayc commented 3 months ago

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

GregForkutza commented 3 months ago

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.

ismayc commented 3 months ago

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 commented 3 months ago

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.

GregForkutza commented 3 months ago

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.

ismayc commented 3 months ago

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

GregForkutza commented 3 months ago

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

ismayc commented 3 months ago

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  
GregForkutza commented 3 months ago

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.

ismayc commented 3 months ago

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

GregForkutza commented 3 months ago

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?

ismayc commented 3 months ago

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!

andreifoldes commented 3 weeks ago

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