TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I have tried this sample with pdflatex tmp.tex


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
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, loaded.
Document Class: extarticle 1996/10/08 v1.0 Non Standard LaTeX document class
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
up vote 39 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:

Pipe sign: |


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
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
\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
When I used this method my word exceeds the page width. How can I avoid that? My two words are \texttt{--}genotyping_mode GENOTYPE_GIVEN_ALLELES. – tommy.carstensen Sep 15 '15 at 10:27

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

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
   \input"|octave -qf --eval 'format #1;disp(#2)'"


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

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


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
Not that this has anything to do with the original question :) – Will Robertson Aug 21 '10 at 2:00

Your Answer


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.