LaTeX Socket Error: Cannot knit Rmd Document

Hi!
I'm in the middle of writing up my thesis and I am using a bookdown template provided by my university but have run into an issue with knitting the complete document to a pdf.

The error I get when I try to knit is the following:
! LaTeX socket Error: Sockets can only be declared at top-level!

I was originally able to resolve the issue by uninstalling the tinytex package and then reinstalling it, but that isn't working anymore and I can't find a solution elsewhere. The .tex file is created fine, the error occurs as a result of compiling the file to a pdf. When I try and compile the tex file directly the error seems to occur in the hyperred.sty file, but again I have no idea why this error is occurring or how to fix it.

I have already tried updated both R Studio and R itself.

Would really appreciate if someone could help with this!

Here is the bottom section of my log for reference:
\Hy@SavedSpaceFactor=\count411

! LaTeX socket Error: Sockets can only be declared at top-level!

For immediate help type H .
...

l.2080 {\providecommand\UseSocket[2]{#2}}

Here is how much of TeX's memory you used:
15151 strings out of 476232
275852 string characters out of 5795949
1924530 words of memory out of 5000000
36931 multiletter control sequences out of 15000+600000
562584 words of font info for 39 fonts, out of 8000000 for 9000
14 hyphenation exceptions out of 8191
81i,0n,95p,542b,9378s stack positions out of 10000i,1000n,20000p,200000b,200000s

! ==> Fatal error occurred, no output PDF file produced!

For reference, cross posted at

This error seems link to LaTeX socket usage.

It is base LaTeX so kind of unexpected. You should ask on specified LaTeX forum maybe.

Did you try to update LaTeX already ?

I'm having this same issue.

Yeah I've tried to update LaTeX, as well as uninstalling and reinstalling it, both on my system and in R itself (tinytex package in R). It doesn't make any difference unfortunately.

This is a weird error indeed. It seems to come from LaTeX itself - but strange that no occurence about this issue elsewhere.

This has been open at

and we'll see what we can found. If you have reproducible example that would help a lot !

It seems to come for LaTeX package update

See discussion on Github issue.

The problem seems to be that \spacing{...} is used as a command, but it is an environment.

You should check in the template used with Book to understand how this command gets used in your TeX Document.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.