I'm working on latex and R (swaeave) and I am using utf8
encoding but when I use \textbf{dataset}
, the text is not bold. Below is part of my code. But I am not sure what is reason behind it.
\documentclass[11pt,table,a4paper]{article}
\usepackage[T1,T2A]{fontenc}
\usepackage{CJKutf8}
\usepackage[english,russian]{babel}
\begin{document}
%chunk = 1
<<echo=FALSE,results=tex>>=
cat("dataset","\n")
cat("\\textbf{dataset}","\n") # it should be bold
@
\end{document}linecolor=goldenpoppy
The error is due to \usepackage[english,russian]{babel}
. Please help me out in fixing this pblm.
Best Answer
UPDATE: See the solution at point 4.
I don't really understand the question. Apparently you are trying to insert some R code inside your latex document, but didn't take into account that some characters used in the listing have special meaning for latex.
For example, you have
%chunk=1
, but since%
is the comment character for TeX, that line will be ignored. Then you have some\n
inside, but since\
is the escape character for TeX, it complains about\n
not being defined. Oddly enough, you doubled the\
beforetextbf
, sotextbf
is not a tex command anymore in that context (while\\
is the command for a newline). Also you have#
to introduce a comment in R, but#
is a special char used by tex to denote an argument.All these errors are not related to
\usepackage[english,russian]{babel}
, as you suggest. They are instead the usual errors which happen when you insert code from some other language into tex, without "protecting" it in a verbatim environment. Also, you have an extraneouslinecolor=goldenpoppy
after\end{document}
, which will be ignored (what was it for, anyway?)While more clarifications about your actual problem arrive, I can try guessing and suggesting some solutions.
Solve the errors and get a compilable document. Use
verbatim
to disable the special meaning of all those special chars.Result:
Use
listings
package to get syntax highlight for R (comments are italized, keywords are bold, etc.)Result:
I guess that you want the text "dataset" to be typeset in bold. If you use
verbatim
, the command\textbf
is not "executed" (because\
has lost its status of escape char). So you need a verbatim environment which disables most of the scpecial chars, but still allows for\
as escape.Fancyvrb
package has such an option. Unfortunately in that case\n
would be interpreted also as a command. An easy solution is to define that command.But, oh! The result shows no bold (perhaps this was your actual problem?):
In this case this is because your
tt
font has not bold variant. And this could be related to the cyrillic fonts you use. Please, confirm if this is the intended question.UPDATED: Once it has been confirmed (in a comment) that the problem was not the syntax errors found in the (non-working) minimal example, but instead the lack of an appropiate
tt
bold font, the solution is to provide such a font. Typically the solution would be as simple as to\usepackage{extra-bold}
, which installs bold versions ofcmtt
font. However this does not work either in this case, because this package installs those fonts under the 'OT1' enconding, but the document usesT2A
encoding.A "brute force" solution is to fool latex into "thinking" that font
cmttb
hasT2A
encoding. This works for the minimal example provided because the listing contains only ascii characters. I don't know what would happen if the listing had contained cyrillic or chinese characters. You have to try yourself.In order to implement this "solution" (note the quotes), you have to write a file, called
myboldtt.sty
for example, in the same folder than your main document. The content of this file would be:And then ensure that
\usepackage{myboldtt}
appears in your main document. A MWE follows:Which (at last!) produces the intended output:
NOTE: You need to have cm-mf-extra fonts also installed in your system.