Chinese in LaTeX - latex

2nd post on Stack Exchange, not 100% sure this is the correct place to post, but I'll move it if it needs to be moved.
I've been trying to learn how to type up my Chinese documents in LaTeX (I use ShareLaTeX), but almost nothing seems to work. Although I have all of the proper Chinese fonts installed on the computer, it continues giving me errors, even when I tried to run the document that ShareLateX itself used for an example.
Below are some documents and the errors/problems they cause.
\documentclass{article}
\usepackage{CJK}
\usepackage[utf8]{inputenc}
\begin{document}
\title{Title}
\author{Author}
\date{February 2015}
\begin{CJK}{UTF8}{gbsn}
你好\\
文章内容\\
Something\\
再见\\
\end{CJK}
\end{document}
This gives out a document that is the closest I've had to success, but it doesn't print out in proper formatting (namely, the Title, Author and Date are all absent) and it doesn't have the usual margins.
The next one was also stolen from an example
\documentclass{ctexart}
\setCJKmainfont{simsun.ttf}
\setCJKsansfont{simhei.ttf}
\setCJKmonofont{simfang.ttf}
\begin{document}
\tableofcontents
\begin{abstract}
这是在文件的开头的介绍文字.本文的主要话题的简短说明.
\end{abstract}
\section{ 前言 }
在该第一部分中的一些额外的元素可以被添加。巴贝尔包将采取的翻译服务.
\section{关于数学部分}
在本节中的一些数学会使用数学模型含中文字符显示。
這是一個傳統的中國文字
\end{document}
It returns the following error messages and fails to compile. All issues are in main.tex unless otherwise stated
Compile Error
Undefined Control Sequence (line 3)
LaTeX Error: Missing \begin[document} (line 3)
Undefined Control Sequence (line 5)
Improper Alphabetic Constant (output.toc, line 1)
Missing = inserted for \ifnum (output.toc, line 1)
Missing number, treated as 0 (out..., line 1)
Bad character code (-30). (out..., line 1)
Undefined control sequence (line 12)
Package CJK Error: Invalid Character Code (line 12)
Undefined Control Sequence (line 15)
Undefined Control Sequence (line 15)
Undefined Control Sequence (line 16)
Undefined Control Sequence (line 16)
Undefined Control Sequence (line 19)
Undefined Control Sequence (line 21)
dfTeX error: pdflatex (file simsun.ttc): cannot open TrueType font file for reading
Optimally, I'd like to use the KaiTi font, but for now I'll just settle for being able to created a document in the first place. :)

Related

Missing number treated as zero error when using titlesec package and tableofcontents

Whenever I use the package titlesec and later the command \tableofcontents I get the following error:
I created the following MRE below
! Missing number, treated as zero. <to be read again>}\tableofcontents
In the past this never happened, but since I installed MikTex on my new laptop, those lines below do not work anymore.
Removing the package titlesec seems to work, but I would rather know the actual reason for this problem.
\RequirePackage{fix-cm}
\documentclass[
%draft,
pdftex,
paper=a4,
%paper=portait, % Paper Setting
pagesize=auto,
fontsize=11pt, % Font Size
version=last, % Version
%headsepline, % Line after header
%footsepline, % Line before footer
]{scrartcl}
\KOMAoptions{parskip=true}
% Depth of content table
\usepackage{titlesec}
\begin{document}
\tableofcontents
\newpage
Test
\end{document}

knitr: fig.height must be numeric in new version?

I downloaded a new version of the knitr package and suddenly I get the following error when trying to include a plot in an Rnw file:
Error in options[[sprintf("fig.%s", i)]] * options$dpi :
non-numeric argument to binary operator
Calls: knit ... process_group.block -> call_block -> fix_options -> %n%
After a lot of experimenting I found out the problem is with the command fig.height, apparently it is supposed to be numeric. This code produces the error:
\documentclass{article}
\begin{document}
<<cat, fig.cap="dog", fig.height='\\textheight'>>=
plot(c(1, 2, 3), c(2, 1, 3))
#
\end{document}
This code does not:
\documentclass{article}
\begin{document}
<<cat, fig.cap="dog", fig.height=6>>=
plot(c(1, 2, 3), c(2, 1, 3))
#
\end{document}
Unfortunately I have no idea what the unit of measurement for this 6 is.
This code:
\documentclass{article}
\begin{document}
<<cat, fig.cap="dog", fig.height=6cm>>=
plot(c(1, 2, 3), c(2, 1, 3))
#
\end{document}
produces a different error:
Error in base::parse(text = code, srcfile = NULL) :
1:44: unexpected symbol
1: alist( 'cat', fig.cap="dog", fig.height=6cm
^
Calls: knit ... withCallingHandlers -> eval -> parse_only -> <Anonymous>
Execution halted
All in all it seems as if knitr is really expecting a numeric value for fig.height, which is moderately annoying because I have already typed a lot of fig.height='\\textheight' commands throughout my document (back in the days that that still worked) and I also do not really know what the numeric value corresponding to Latex's \textheight is.
Any advise?
UPDATE: I did some more experimenting and it turns out that the numbers you feed to fig.height appear nowhere in the Latex-file, instead they influence the dimension of the cat.pdf image produced by knitr directly. This kind of suggest that leaving out fig.height altogether might be the best strategy. Still this doesn't tell us how to get the [height=\textheight] in the tex document.
Use the chunk option out.height instead of fig.height.

Sweave to LaTeX "undefined control sequence" error

Im trying to include some R results in a TeX document using RStudio. I have managed to get RStudio to generate, what to me looks to be, a fine tex file but it fails to compile the pdf.
I get errors returned saying ! Undefined control sequence. ' which seems to be returned due to the first lines of str(data) calls and the lines showing significance levels:
"! Undefined control sequence.
<argument> '
data.frame': 1980 obs. of 5 variables:
l.39 'data.frame': 1980 obs. of 5 variables:
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."
"! Undefined control sequence. <argument>
Signif. codes: 0 '
***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
l.95 ...**' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
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."
Files with just the summary(data) for instance work fine
Looking around other mailing lists etc Ive seen that this could be because tex cannot find the Sweave package so have copied it to various locations (the same folder as the Rnw and tex files, and a directory without spaces in the path) and tried to rerun the file. Nothing seems to work.
Similarly, this doesnt work, but using summary(cars) instead of str(cars) does. This suggests to me that its something to do with the ' character.
\documentclass [a4paper]{article}
\usepackage{Sweave}
\title {Sweave Example 1}
\author {Friedrich Leisch}
\begin {document}
\maketitle
In this example we embed parts of the examples from the
\texttt {kruskal.test} help page into a \ LaTeX {} document :
<<>>=
data ( cars )
str(cars)
#
\end{document}
(adapted from the sweave manual)
Any ideas on what Im doing wrong?
Any suggestions would be much appreciated.
Add the [noae] package option to your \usepackage{Sweave} statement.

Figures occurring after ^ and _ macros (was: LaTeX limitation?)

I've hit an annoying problem in LaTeX. I've got a tex file of about 1000 lines. I've already got a few figures, but when I try to add another figure, It barfs with:
! Undefined control sequence.
<argument> ... \sf#size \z# \selectfont \#currbox
l.937 \begin{figure}[t]
If I move the figure to other parts of the file, I can get similar errors on different lines:
! Undefined control sequence.
<argument> ... \sf#size \z# \selectfont \#currbox
l.657 \paragraph
{A Centering Algorithm}
If I comment out the figure, all is ok.
%\begin{figure}[t]
% \caption{Example decision tree, from Reiter and Dale [2000]}
% \label{fig:relation-decision-tree}
% \centering
% \includegraphics[keepaspectratio=true]{./relation-decision-tree.eps}
%\end{figure}
If I keep just the begin and end like:
\begin{figure}%[t]
% \caption{Example decision tree, from Reiter and Dale [2000]}
% \label{fig:relation-decision-tree}
% \centering
% \includegraphics[keepaspectratio=true]{./relation-decision-tree.eps}
\end{figure}
I get:
! Undefined control sequence.
<argument> ... \sf#size \z# \selectfont \#currbox
l.942 \end
{figure}
At first, I thought maybe LaTeX has hit some limit, and I tried playing with the ulimits, but that didn't help. Any ideas?
i've got other figures with graphics already. my preamble looks like:
\documentclass[acmcsur,acmnow]{acmtrans2n}
\usepackage{array}
\usepackage{lastpage}
\usepackage{pict2e}
\usepackage{amsmath}
\usepackage{varioref}
\usepackage{epsfig}
\usepackage{graphics}
\usepackage{qtree}
\usepackage{rotating}
\usepackage{tree-dvips}
\usepackage{mdwlist}
\makecompactlist{quote*}{quote}
\usepackage{verbatim}
\usepackage{ulem}
I found, not that it's a problem with \textsuperscript, but that it's with a ^ def I picked up from http://anthony.liekens.net/index.php/LaTeX/SubscriptAndSuperscriptInTextMode . The fix is to put the use of ^ in {}, as in I've put entire sections where I use lots of ^ and _ in {}. Hurrah!
During the end of my Master Thesis I also had the problem that after some amount of figures, I got an error without any special error message. After I read you thread, I also tried something with the packages included and in the end I was successful by taking out the \usepackage{pxfonts} and \usepackage{txfonts}. Yeah, finally.. I almost went crazy.. ;)
If I Google for "latex undefined control sequence" I get this.
I've successfully included a graphic into LaTeX using something like this:
\usepackage{amsmath,amsthm,graphicx}
...
I just wanted to test adding an image to a \LaTeX file:
\includegraphics[scale=0.60]{basic-info.png}
I typeset an entire dissertation of 200 pages with lots of figures in LaTeX and didn't run into a limit like that. I'd bet on a syntax problem first before I'd assume a size issue.
Your error lies elsewhere. I wouldn't be the least surprised if it turned out to be the document class. Try altering your document for \documentclass{article} and see where you get. If that fixes the problem you can complain to the ACM (ROTFLMAO—I've dealth with ACM).
If that doesn't fix, the problem, slip in a \tracingall somewhat before the offending figure or section, put the results into http://pastebin.com/, and let us know.
Please receive the thanks of a (formerly) utterly-confounded graduate student. Quick clarification for other users:
{The quickest ^{way} to put this solution into practice is to bracket all sections of text involving the character ``\^'' as shown here.}

Latex listings-package format option for uppercase keywords

I use the listings package to insert source code. I would like to print all keywords uppercase in the output, regardless of the case in the input.
The manual states that
keywordstyle=[number][*]style
produces just what I want. However the following (almost) minimal example does not work.
if I set keywordstyle to "[1][]{\bfseries}" I end up with "[]" in front of every keyword
and "[*]{\bfseries}" gives me an asterisk in the start of the document.
I also tried "\MakeUppercase" and "{\MakeUppercase}" for keywordstyle which resulted in several errors, the first being:
! Incomplete \iffalse; all text was ignored after line 11
Minimal example:
\documentclass{article}
\usepackage{listings}
\lstdefinelanguage{KA_assembler}
{morekeywords={add,and,or,xor},
keywordstyle=[1][*]{\bfseries},
sensitive=false,
}
\lstset{language=KA_assembler}
\begin{document}
\begin{lstlisting}
and %r1, %r2
xor %r2, %r3
and %r4, %r5
\end{lstlisting}
\end{document}
I use Miktex for compilation of the tex files. So how do I force uppercase for Keywords?
In the manual, the brackets around the * look a bit different then the brackets around number. The reason is that the brackets around * are not meant to be used in the latex code, they just indicate that the presence of the * is optional. So try
keywordstyle=[1]*\bfseries
or
keywordstyle=*\bfseries
- it worked for me.

Resources