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

4 Answers 4


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.

  • 2
    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.) Commented Aug 15, 2010 at 19:06
  • @ShreevatsaR: I've added links to the encoding tables and a brief explanation.
    – Stefan Kottwitz
    Commented Aug 15, 2010 at 19:46
  • There's also a encoding table at latex-project.org/help/documentation/encguide.pdf
    – user202729
    Commented Jun 26, 2022 at 7:55

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.

  • 6
    \usepackage[T1]{fontenc} should be added anyway, because it fixes a lot of font-related problems.
    – Caramdir
    Commented Jan 19, 2011 at 16:50
  • 2
    I wasn't aware of $\vert$. I've been using $\mid$, which looks identical to me.
    – DJP
    Commented Jul 29, 2011 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. Commented Sep 15, 2015 at 10:27
  • 2
    The difference between $\mid$ and $\vert$ appears to be spacing around the symbol, which $\mid$ has and $\vert$ doesn't. Also, $|$ lacks spacing around it. Unfortunately, using $\bigg$ on $\mid$ results in an error.
    – shs
    Commented Jan 5, 2021 at 9:49

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

  • 2
    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
    Commented Jan 18, 2012 at 13:05
  • 1
    Yes @matth, you are of course right. I guess when reading this question my eyes glazed over {fontenc} and I read in incorrectly.
    – david
    Commented May 16, 2012 at 15:06
  • \texttt{A\textbar{}B} produces homogeneous formatting.
    – Erwann
    Commented Jan 22, 2022 at 5:54
  • The {} is redundant and kind of bad practice as well (it breaks kerning). Just do \texttt{A\textbar B}.
    – user202729
    Commented Nov 18, 2022 at 4:54

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.

  • I've recently been told that this is also supported in TeX Live with -shell-escape. Commented Aug 21, 2010 at 2:00
  • 5
    Not that this has anything to do with the original question :) Commented Aug 21, 2010 at 2:00

You must log in to answer this question.

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