1

When I try to set org-latex-classes with the following code:

(setq org-latex-classes
      '(("article"
         "
\\documentclass[12pt,a4paper]{article}

\usepackage{xeCJK}
%\usepackage[heading]{CJK}
\usepackage{zhnumber} % package for Chinese formatting of date time (use /zhtoday)
%\usepackage[yyyymmdd]{datetime} % set date time to numeric

% Set default indentation

\setlength\parindent{12pt}

% Set Paper Size, Page Layout (another variable is 'bindingoffset')
\usepackage[margin = 1.5in, paper = a4paper, inner = 2.5cm,
outer = 2.5cm, top = 3cm, bottom = 2.5cm]{geometry}

% Keep paragraph indentation while having a line break in between paragraphs.
\edef\restoreparindent{\parindent=\the\parindent\relax}
\usepackage{parskip}
\restoreparindent

% Indent first paragraph.
\usepackage{indentfirst}

\usepackage{titlesec}
\usepackage{titling}
\usepackage{fontspec} % packages for title and section-heading font setting.

% Set Font.
\setsansfont{Arial}
\setmainfont{Calibri} % Set serifed font to Calibri. Originally set to 'Times New Roman', but it cannot display certain characters such as ①②③.
\setCJKmainfont{MingLiU}
\setCJKsansfont{Kaiti TC} % Set Chinese font. NOTE: Remember to append CJK before of the font class. CJK HAS to be there for the font to show.

\titleformat*{\section}{\fontsize{16}{18}\bfseries\sffamily}
\titleformat*{\subsection}{\fontsize{14}{16}\bfseries\sffamily}
\titleformat*{\subsubsection}{\fontsize{12}{14}\bfseries\sffamily} % Set formats for each heading level. 'sffamily' will point to the sans-serif font. In this case, 「楷體」.
\renewcommand{\maketitlehooka}{\sffamily} % Set title font.

% Set quotation font.
\usepackage{etoolbox}
\newCJKfontfamily\quotefont{Kaiti TC}
\AtBeginEnvironment{quote}{\quotefont\normalsize}

% Tweak default settings.
\renewcommand{\baselinestretch}{1.2} % Set line width.
\renewcommand{\contentsname}{目次} % Translate content page title to Chinese. (Could possibly be done automatically with '\usepackage[heading]{CJK}'. TODO experiment. )

% For text-boxes

\usepackage{mdframed}
\BeforeBeginEnvironment{minted}{\begin{mdframed}}
\AfterEndEnvironment{minted}{\end{mdframed}}

% [FIXME] ox-latex 的設計不良導致 hypersetup 必須在這裡插入
\\usepackage{hyperref}
\\hypersetup{
  colorlinks=true, %把紅框框移掉改用字體顏色不同來顯示連結
  linkcolor=[rgb]{0,0.37,0.53},
  citecolor=[rgb]{0,0.47,0.68},
  filecolor=[rgb]{0,0.37,0.53},
  urlcolor=[rgb]{0,0.37,0.53},
  pagebackref=true,
  linktoc=all,}
"
         ("\\section{%s}" . "\\section*{%s}")
         ("\\subsection{%s}" . "\\subsection*{%s}")
         ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
         ("\\paragraph{%s}" . "\\paragraph*{%s}")
         ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
        ))

I get this error:

Debugger entered--Lisp error: (error "Non-hex digit used for Unicode escape")

The debugger reveals that the error lies on this line: \usepackage{xeCJK}

But I can't seem to figure out what's wrong with the code. A LaTex file containing the same line compiles without any error.

0

I just found out what's wrong. Elisp requires a backslash in a string (i.e., between double-quotes "") to be escaped in Lisp, so the following code works:

(setq org-latex-classes
      '(("article"
         "
\\documentclass[12pt,a4paper]{article}

\\usepackage{xeCJK}
%\\usepackage[heading]{CJK}
\\usepackage{zhnumber} % package for Chinese formatting of date time (use /zhtoday)
%\\usepackage[yyyymmdd]{datetime} % set date time to numeric

% Set default indentation

\\setlength\\parindent{12pt}

% Set Paper Size, Page Layout (another variable is 'bindingoffset')
\\usepackage[margin = 1.5in, paper = a4paper, inner = 2.5cm,
outer = 2.5cm, top = 3cm, bottom = 2.5cm]{geometry}

% Keep paragraph indentation while having a line break in between paragraphs.
\\edef\\restoreparindent{\\parindent=\\the\\parindent\\relax}
\\usepackage{parskip}
\\restoreparindent

% Indent first paragraph.
\\usepackage{indentfirst}

\\usepackage{titlesec}
\\usepackage{titling}
\\usepackage{fontspec} % packages for title and section-heading font setting.

% Set Font.
\\setsansfont{Arial}
\\setmainfont{Calibri} % Set serifed font to Calibri. Originally set to 'Times New Roman', but it cannot display certain characters such as ①②③.
\\setCJKmainfont{MingLiU}
\\setCJKsansfont{Kaiti TC} % Set Chinese font. NOTE: Remember to append CJK before of the font class. CJK HAS to be there for the font to show.

\\titleformat*{\\section}{\\fontsize{16}{18}\\bfseries\\sffamily}
\\titleformat*{\\subsection}{\\fontsize{14}{16}\\bfseries\\sffamily}
\\titleformat*{\\subsubsection}{\\fontsize{12}{14}\\bfseries\\sffamily} % Set formats for each heading level. 'sffamily' will point to the sans-serif font. In this case, 「楷體」.
\\renewcommand{\\maketitlehooka}{\\sffamily} % Set title font.

% Set quotation font.
\\usepackage{etoolbox}
\\newCJKfontfamily\\quotefont{Kaiti TC}
\\AtBeginEnvironment{quote}{\\quotefont\\normalsize}

% Tweak default settings.
\\renewcommand{\\baselinestretch}{1.2} % Set line width.
\\renewcommand{\\contentsname}{目次} % Translate content page title to Chinese. (Could possibly be done automatically with '\\usepackage[heading]{CJK}'. TODO experiment. )

% For text-boxes

\\usepackage{mdframed}
\\BeforeBeginEnvironment{minted}{\\begin{mdframed}}
\\AfterEndEnvironment{minted}{\\end{mdframed}}

% [FIXME] ox-latex 的設計不良導致 hypersetup 必須在這裡插入
\\usepackage{hyperref}
\\hypersetup{
  colorlinks=true, %把紅框框移掉改用字體顏色不同來顯示連結
  linkcolor=[rgb]{0,0.37,0.53},
  citecolor=[rgb]{0,0.47,0.68},
  filecolor=[rgb]{0,0.37,0.53},
  urlcolor=[rgb]{0,0.37,0.53},
  pagebackref=true,
  linktoc=all,}
"
         ("\\section{%s}" . "\\section*{%s}")
         ("\\subsection{%s}" . "\\subsection*{%s}")
         ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
         ("\\paragraph{%s}" . "\\paragraph*{%s}")
         ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
        ))

LaTex itself doesn't need doubled backslashes.

  • 1
    C-h i, Elisp manual, i backsla TAB, choose completion backslash in strings. That takes you to manual node Syntax for Strings. – Drew Aug 28 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.