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.

How to insert pipe symbol | in TeX (LaTeX)?

I have tried this sample with pdflatex tmp.tex

\documentclass{extarticle}
\begin{document}
\textpipe
\end{document}

And it give undefined control sequence error

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
restricted \write18 enabled.
entering extended mode
(./tmp.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, loaded.
(/usr/share/texmf-texlive/tex/latex/extsizes/extarticle.cls
Document Class: extarticle 1996/10/08 v1.0 Non Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo)
(/usr/share/texmf-texlive/tex/latex/base/exscale.sty))
No file tmp.aux.
! Undefined control sequence.
l.3 \textpipe
share|improve this question
    
The link to the original SO question: stackoverflow.com/questions/3487966/… –  Stefan Kottwitz Aug 15 '10 at 15:57

4 Answers 4

up vote 28 down vote accepted

The pipe symbol may be used directly in the input and will produce the desired output if you use T1 font encoding. For example:

\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}
Pipe sign: |
\end{document}

Output:

enter image description here

Compare these tables to see the difference between the two font encodings: OT1 (Standard encoding) vs. T1 (Cork encoding). The OT1 table doesn't contain the pipe symbol, but it can be found in the T1 table. It's position is 7C. With OT1 7C means a wide dash, that's why we get a wide dash instead of the pipe symbol in standard encoding.

See Special LaTeX characters for some more information.

For using the command \textpipe loading a package like tipa or t4phonet is necessary.

share|improve this answer
1  
Ah, another reason to use \usepackage[T1]{fontenc}. I've added this to another answer, but could you explain why this happens, exactly? (Either here or at the post on texblog.) –  ShreevatsaR Aug 15 '10 at 19:06
    
@ShreevatsaR: I've added links to the encoding tables and a brief explanation. –  Stefan Kottwitz Aug 15 '10 at 19:46

It is unnecessary to load any additional packages unless there are other reasons to do so. Mathmode provides alternative symbols $\vert$ for a vertical pipe and $\Vert$ for a double pipe. These appear to be independent of encoding. Actually as a math symbol $|$ appears also to be encoding independent.

share|improve this answer
2  
\usepackage[T1]{fontenc} should be added anyway, because it fixes a lot of font-related problems. –  Caramdir Jan 19 '11 at 16:50
    
I wasn't aware of $\vert$. I've been using $\mid$, which looks identical to me. –  DJP Jul 29 '11 at 17:25

As a side note: MikTeX supports using pipes in \input if you supply the flag -enable-pipes. This is useful for calling external programs directly from your document.

Here is an example of getting input from Octave and a listing of the document files:

%& -enable-pipes
\documentclass{article}
\usepackage{amsmath}
\newcommand\octave[2][]{%
   \input"|octave -qf --eval 'format #1;disp(#2)'"
}

\begin{document}

Foo $\pi \approx \octave{pi}$ bar.
\begin{align}
   \pi           &\approx \octave[long]{pi} \\
   \sqrt 2       &\approx \octave[short]{sqrt(2)} \\
   \pi\exp(3\pi) &\approx \octave[short g]{pi*exp(3*pi)}
\end{align}

{\obeylines
List of files:
\input"|ls -l \jobname.*"
}

\end{document} 

I am using MikTeX on a Linux system. If you are running windows you must make changes to the example accordingly.

share|improve this answer
    
I've recently been told that this is also supported in TeX Live with -shell-escape. –  Will Robertson Aug 21 '10 at 2:00
4  
Not that this has anything to do with the original question :) –  Will Robertson Aug 21 '10 at 2:00

I would recommend using the command \textbar, since this does not require you to use different encoding or additional packages. For me this was a much better solution, as I was already committed to usepackage[utf8]{inputenc}. Also, I am using a system that puts UTF-8 data into LaTeX templates (escaping special characters), and this system cannot rely on any additional packages (other than UTF-8 encoding).

share|improve this answer
1  
I am not sure if you know the difference between input encoding and font encoding. Maybe the following question is interesting for you: tex.stackexchange.com/questions/664/… –  matth Jan 18 '12 at 13:05
    
Yes @matth, you are of course right. I guess when reading this question my eyes glazed over {fontenc} and I read in incorrectly. –  ruquay May 16 '12 at 15: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.