I'm trying to create a command to printout IP addresses on a LaTeX document with a different style. It's really simple what I want to do, but I would like to do it scalable.

I've already done this:


And I was expecting to call the command on the text with the IP address as the argument, like this:


But it isn't working.

I'm really new to LaTeX and trying to give my best on the first "template less" document that I'm writing.

  • Welcome to TeX.SX! What does not working mean
    – user31729
    Commented Oct 12, 2015 at 19:47
  • The IP address appears with the regular LaTeX font and not with the "pcr" font family. Commented Oct 12, 2015 at 19:48

2 Answers 2


Your command doesn't take an argument, so it effectively doesn't do anything. Try this:

\newcommand{\ipAddress}[1]{{\fontfamily{pcr}\selectfont #1}}

LaTeX provides a \texttt command which will set its argument in a monospaced ("teletype") font. So you can write \texttt{}.

Even better, you can use the \let command to make a new macro that is semantically meaningful for you, such as \let\ipAddress\textt and then you can write \ipAddress{}.

The \texttt command will render the text in whatever the default teletype family is. By default this is Computer Modern Typewriter. You can change the default by changing the \ttdefault command to another font family, using the abbreviations from the "New Font Selection Scheme". To set the teletype default to pcr, you would do this:


So below is what I would do if I had to use pcr. You could modify this example to select any teletype font in combination with any other font packages.



The IP address is \ipAddress{}.

Actually I prefer the Computer Modern Teletype, which is designed to harmonize with the rest of the family.

  • This worked flawlessly! Commented Oct 12, 2015 at 19:55
  • Maybe you want to mention \texttt.
    – egreg
    Commented Oct 12, 2015 at 20:07

Is this what you are looking for?


You do not mention which packages/engine you are using so this is my best bet as to what the problem is.

To understand the difference consider the expansion of your macro

\ipAddress{} → {\fontfamily{pcr}\selectfont{}}{}

as you can see the group where the font selection applies is closed before the ip is typeset.

By contrast, mine expands as

\ipAddress{} → {\fontfamily{pcr}\selectfont}

which should do what you want.

In general, when you create a command with \newcommand{\macroname}[N]{DEF} in DEF you can use #1 to #N as placeholders for where you want the N arguments to be used.

As mentioned by @Andrew, if you use line breaks in DEF they get interpreted in the context of the macro expansion so they may mean 'there is a space here' which is not necessarily what you want. To neutralise them while keeping the lines separated in the code, you can make a comment right at the end of those lines.

  • 1
    You need [1] in the definition or LaTeX won't read the #1 argument, right? Commented Oct 12, 2015 at 19:54
  • This does not work: Illegal parameter number in definition of \ipAddress. Commented Oct 12, 2015 at 19:54
  • 1
    Perhaps you want % signs in the command definition to avoid extraneous spaces? Commented Oct 12, 2015 at 20:01
  • yes guys just pressed the wrong button too early =) now it's complete and should work!
    – Bordaigorl
    Commented Oct 12, 2015 at 20:01
  • @AndrewCashner good suggestion for %
    – Bordaigorl
    Commented Oct 12, 2015 at 20:02

You must log in to answer this question.

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