Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
1  
Sorry, but without an MWE few people will be able or willing to help you. For a start clean up your package list: You load everything and the kitchen sink, and you load it twice. –  Martin Schröder Nov 28 '12 at 7:16
    
If i remove unnecessary package then i never face such pblm. The pblm is due to clash of package. –  Manish Nov 28 '12 at 7:29
    
One idea would be, to remove one package after another in order to narrow down the clash you propose to have. If one package is neccessary to produce your problem remove others (that are not involved of course) to further compress your MWE and post that MWE here. –  Ronny Nov 28 '12 at 7:31
7  
Please don't downvote below -1, even if the question in it's current form needs some improvement. A score of -1 is enough to show that the question needs work, anything below that is of no use. Also, if you downvote or vote to close, please leave a comment explaining why you did so. –  Jake Nov 28 '12 at 7:39
5  
This should not have been closed: The question has been improved significantly from its first version. Please wait at least 24 hours after asking the OP for improvements to the question before voting to close. Also, if you downvote, please don't forget to revert the vote after the question is improved. –  Jake Nov 28 '12 at 8:31

1 Answer 1

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 \ before textbf, so textbf 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 extraneous linecolor=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.

  1. Solve the errors and get a compilable document. Use verbatim to disable the special meaning of all those special chars.

    \documentclass[11pt,table,a4paper]{article}
    \usepackage[T1,T2A]{fontenc}
    \usepackage{CJKutf8}
    \usepackage[english,russian]{babel}
    \begin{document}
    \begin{verbatim}
    %chunk = 1
    <<echo=FALSE,results=tex>>=
        cat("dataset","\n")
        cat("\\textbf{dataset}","\n")   # it should be bold
     @
    \end{verbatim}
    \end{document}
    

    Result:

    verbatim

  2. Use listings package to get syntax highlight for R (comments are italized, keywords are bold, etc.)

    \documentclass[11pt,table,a4paper]{article}
    \usepackage[T1,T2A]{fontenc}
    \usepackage{CJKutf8}
    \usepackage[english,russian]{babel}
    \usepackage{listings}
    \begin{document}
    \begin{lstlisting}[language=R]
    %chunk = 1
    <<echo=FALSE,results=tex>>=
    cat("dataset","\n")
    cat("\\textbf{dataset}","\n")   # it should be bold
    @
    \end{lstlisting}
    \end{document}
    

    Result:

    listings

  3. 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.

    \documentclass[11pt,table,a4paper]{article}
    \usepackage[T1,T2A]{fontenc}
    \usepackage{CJKutf8}
    \usepackage[english,russian]{babel}
    \usepackage{fancyvrb}
    \def\n{\textbackslash n}
    \begin{document}
    \begin{Verbatim}[commandchars=\\\{\}]
    %chunk = 1
    <<echo=FALSE,results=tex>>=
    cat("dataset","\n")
    cat("\textbf{dataset}","\n")   # it should be bold
    @
    \end{Verbatim}
    \end{document}
    

    But, oh! The result shows no bold (perhaps this was your actual problem?):

    fancyvrb

    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.

  4. 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 of cmtt font. However this does not work either in this case, because this package installs those fonts under the 'OT1' enconding, but the document uses T2A encoding.

    A "brute force" solution is to fool latex into "thinking" that font cmttb has T2A 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:

    \providecommand{\EC@ttfamily}[5]{%
      \DeclareFontShape{#1}{#2}{#3}{#4}%
      {<5><6><7><8>#50800%
       <9><10><10.95><12><14.4><17.28><20.74><24.88><29.86>%
       <35.83>genb*#5}{}}
    \DeclareFontFamily{T2A}{cmtt}{\hyphenchar\font\m@ne}
    \EC@ttfamily{T2A}{cmtt}{m}{n}{latt}
    \EC@ttfamily{T2A}{cmtt}{m}{sl}{last}
    \EC@ttfamily{T2A}{cmtt}{m}{it}{lait}
    \EC@ttfamily{T2A}{cmtt}{m}{sc}{latc}
    \EC@ttfamily{T2A}{cmtt}{bx}{n}{labtl}
    \DeclareFontShape{T2A}{cmtt}{b}{n}
       {
        <5><6><7><8><9><10><12><10.95><14.4><17.28><20.74><24.88>cmttb10
        }{}
    \DeclareFontShape{T2A}{cmtt}{bx}{n}%
       {<->ssub*cmtt/b/n}{}
    \endinput
    

    And then ensure that \usepackage{myboldtt} appears in your main document. A MWE follows:

    \documentclass[11pt,table,a4paper]{article}
    \usepackage{bold-extra}
    \usepackage[T1,T2A]{fontenc}
    \usepackage{CJKutf8}
    \usepackage[english,russian]{babel}
    \usepackage{fancyvrb}
    \usepackage{myboldtt}
    \def\n{\textbackslash n}
    \begin{document}
    Regular text. \textbf{Bold}.
    \begin{Verbatim}[commandchars=\\\{\}]
    %chunk = 1
    <<echo=FALSE,results=tex>>=
    cat("dataset","\n")
    cat("\textbf{dataset}","\n")   # it should be bold
    @
    \end{Verbatim}
    \end{document}
    

    Which (at last!) produces the intended output:

    Bold tt

    NOTE: You need to have cm-mf-extra fonts also installed in your system.

share|improve this answer
    
Yes! Just to inform, posted code is sweave code (R & Latex) which is part of my big code (2000 lines). Now pblm is dataset should be in bold but i m not getting desired outptut. –  Manish Nov 29 '12 at 2:27
    
Answer updated to show a possible solution. –  JLDiaz Nov 29 '12 at 15:50
    
JLDiaz@ i have extra bold and myboldtt.sty but still same pblm. \documentclass[11pt,table,a4paper]{article} \usepackage{bold-extra} \usepackage[T1,T2A]{fontenc} \usepackage{CJKutf8} \usepackage[english,russian]{babel} \usepackage{fancyvrb} \usepackage{myboldtt} \begin{document} <<echo=FALSE,results=tex>>= cat("dataset","\n") cat("\\textbf{dataset}","\n") # it should be bold @ \end{document} –  Manish Nov 30 '12 at 1:26
    
@Manish You need to have cm-mf-extra fonts also installed in your system. I added a final note in my answer. –  JLDiaz Nov 30 '12 at 8:42
    
I just checked all cm pakcage arelady there in cmbcsc10.mf cmbtex10.mf cmbtt10.mf cmbtt8.mf cmbtt9.mf cmexb10.mf cmttb10.mf are already there in /usr/local/texlive/2012/texmf-dist/fonts/source/public/cm/. Still i m facing same pblm . –  manish Dec 4 '12 at 8:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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