11

I want to insert an in-line equation with the symbol of Real Number as the code below:

Let $X$ be a continuous random variable with CDF $F(x) = log_{c}(x)$
where $x \in [1,c]$ and $c \in \R_{++}$.

LaTex gives me this error "Undefined control sequence ..." when inserting \R.

Don't know why this happens. Maybe it's related to the amsmathpackage.

This my preamble:

\documentclass[12pt, a4wide]{article}

\usepackage{graphicx}
\usepackage{color}

\usepackage{framed}
\usepackage{alltt}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{enumerate}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage{longtable}
\usepackage{pdflscape}
\usepackage[backref=page]{hyperref}
\usepackage[labelfont=bf]{caption}
\usepackage{capt-of}
\usepackage{adjustbox}
\usepackage{amsmath,amsfonts,amssymb}
%\usepackage{showframe}
\usepackage[authoryear]{natbib}
\usepackage{float}

\usepackage{tikz}
\usepackage{environ}
\makeatletter
\newsavebox{\measure@tikzpicture}
\NewEnviron{scaletikzpicturetowidth}[1]{%
  \def\tikz@width{#1}%
  \def\tikzscale{1}\begin{lrbox}{\measure@tikzpicture}%
  \BODY
  \end{lrbox}%
  \pgfmathparse{#1/\wd\measure@tikzpicture}%
  \edef\tikzscale{\pgfmathresult}%
  \BODY
}
\makeatother

\usepackage{booktabs}

\usepackage[all]{nowidow}
\widowpenalty=1000

\addtolength{\footnotesep}{1mm}
\skip\footins=4ex plus 1ex
\usepackage{lipsum}
\usepackage[bottom,norule,hang]{footmisc}

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{University Name}
\chead{}
\rhead{Course Name}
%\lfoot{Student Name}
\cfoot{\thepage}
%\rfoot{Student ID}
\renewcommand{\headrulewidth}{0.0pt}
\renewcommand{\footrulewidth}{0.0pt}

I know there are lots of packages. Maybe there some problems among them.

1
  • Did you mean \Re?
    – JPi
    Commented Sep 3, 2016 at 21:18

1 Answer 1

34

\R is not a predefined command, you need to define it yourself if you want to use it as a shortcut.

\newcommand{\R}{\mathbb{R}}

Thus:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

\newcommand{\R}{\mathbb{R}}

\begin{document}

Let $X$ be a continuous random variable with CDF $F(x) = \log_{c}(x)$
where $x \in [1,c]$ and $c \in \R_{++}$.

\end{document}

enter image description here

Note \log for log.

4
  • @FrancescoBianchi note that a lot of folks here would call such shortcuts silly. Best (IMO) to redefine an existing command like \Re. Commented Sep 3, 2016 at 23:19
  • 4
    @SeanAllred I'm not a fan of one-letter shortcuts like this myself (even though the consensus I've seen is that the fact that they are one-letter is not the problem per se), but I think it'd be a shame to override \Re, which has a distinct and separate office (used for the real part of a complex number, rather than the set of real numbers). If I were selecting a name for a command, I'd probably use \reals (assuming it's undefined) but it becomes questionable whether that really saves you much time, especially if you're using an editor/IDE which can input the \mathbb{} part for you
    – Au101
    Commented Sep 3, 2016 at 23:28
  • Still, the whole logical structure approach, defining commands for objects and structures does then come into play
    – Au101
    Commented Sep 3, 2016 at 23:29
  • 3
    @Au101 well I guess that's what I get for not taking complex analysis ;) And honestly, \Reals would be better than \mathbb all over the place – at least the former has semantic meaning :) Commented Sep 3, 2016 at 23:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .