1

I am using MikTeX 2.9 on Windows 8.1. The PDF output of the Following TeX file does not display the word "example" in fore color or background color. I'm using TeXWorks editor - that comes with MikTeX - to generate the PDF:

\documentclass{article}
\begin{document}
This is an {\color{green}example} of fore color text.
This is an \colorbox{green}{example} of highlighted text.
\end{document}
nam
  • 1,105

1 Answers1

1

add

\usepackage{color}

to the preamble

David Carlisle
  • 757,742
  • 1
    Wouldn't it be better to send them straight to xcolor, or are there advantages of color? – Steven B. Segletes May 12 '15 at 16:54
  • @David, I followed your suggestion. Now, I'm getting the following error: "The required file tex\context\base\supp-pdf.mkii is missing. It is a part of the following package: mptopdf". I thought the MikTeX would include the color package by default. It does display all my amsmath correctly without installing any extra packages. – nam May 12 '15 at 17:04
  • 1
    MiKTeX includes perhaps xolor by default, but it is not part of base LaTeX, so that you have to load it. Also you should load xcolorrather than color, as @Steven B. Segletes commented. – Bernard May 12 '15 at 17:15
  • 1
    @nam You can also write the text colour as \textcolor{green}{hello}. – Alenanno May 12 '15 at 17:24
  • @StevenB.Segletes personally I'd use color:-) – David Carlisle May 12 '15 at 17:32
  • @nam no you need \usepackage{amsmath} to use the ams math environments (or a class that does that, such as amsart) It is not loaded by default. – David Carlisle May 12 '15 at 18:07
  • @nam you (apparently) need to use the miktex package manager to install mptopdf which seems strange, did you do a minimal initial installation? – David Carlisle May 12 '15 at 18:09
  • After I installed mptopdf package (size: 153202 bytes), the David's suggestion worked. I used this package over xcolor (size: 968805 bytes) because of the size difference between the two. xcolor probably has extra functionality available that I don't need. xcolor was not installed by default either. – nam May 12 '15 at 18:15
  • @David, I did do the minimal initial installation (if I recall correctly). It's working with the amsmath without using \usepackage{amsmath}. I also checked in the miktex package manager that amsmath package was among the installed packages and it's installation date shows as the date when I installed the MikTex. I installed MikTeX on Jan 4, 2015. – nam May 12 '15 at 18:23
  • @David, You are absolutely correct. While the following works without \usepackage{amsmath}: \begin{eqnarray} x^2 + y^2 &=& 1 \\ y &=& \sqrt{1 - x^2}. \end{eqnarray} The following gives an error (if not using the \usepackage{amsmath} in the preamble) as: "LaTeX Error: Environment align* undefined": \begin{eqnarray} x^2 + y^2 &= 1 \\ y &= \sqrt{1 - x^2}. \end{eqnarray}. – nam May 12 '15 at 20:40
  • 1
    eqnarray is in the latex format (and shouldn't be used) you should use amsmath environments instead. @nam – David Carlisle May 12 '15 at 21:01
  • I think you're very biased in your preference for color, David :-) xcolor is just... plain better. @nam, see http://tex.stackexchange.com/q/89763/17423. Also, if you don't have xcolor installed by default, you likely chose a very minimal installation with automatic package installation. I guarantee you will have problems if you continue to use TeX like this. – Sean Allred May 12 '15 at 22:04
  • @SeanAllred yes sure but (a) you should let a bloke use his own packages and (b) for the example in the question, color is all you need, and is guaranteed to be in any LaTeX installation. – David Carlisle May 12 '15 at 22:08
  • (a) :-) (b) Very true, but it's often better to Keep Things Simple (tm) by loading more encompassing packages. I would at least note in the answer that xcolor is preferred when available (and very often loaded by other packages anyway) even if color is all that's required here. Your answer is correct, it's just not good for beginners, in my honest opinion :) – Sean Allred May 12 '15 at 22:10
  • 1
    I think @SeanAllred missed the humor in your comment about color over xcolor. If the package developer doesn't stand up for his own package, who will? It's why I put up with abuse for stacking things that are traditionally done via the amsmath environments. – Steven B. Segletes May 14 '15 at 15:11
  • @StevenB.Segletes oh no I understand :) I'm just advising OP who may not know any better :) and by the way, those answers of yours prove just how versatile your stack engine is :) there's nothing wrong with promoting your own package, it just makes sense to eventually give a newbie all the information :) – Sean Allred May 14 '15 at 16:01
  • @SeanAllred although in this case I'm not sure I agree, color is the standard in the same way article is. In both cases there are better more fully featured alternatives, but for a beginner starting with the version that appears in tutorials and the official latex manual is surely not bad advice. (Apart from which I've not personally used xcolor (although I've read its code a couple of times) so I'd have to look up any syntax examples that were not the same as color. (same comments to whoever downvoted if that isn't you:-) – David Carlisle May 14 '15 at 16:23
  • @DavidCarlisle I wouldn't downvote an answer that works :) in that sense, I would agree with you. I suppose I just wish there were well-known resources for 'second phase' learners of TeX and friends – if not, I suppose I'll just have to write one :) – Sean Allred May 14 '15 at 16:26