5

Is there anyway to find and remove ligatures from tex file? Sometimes when I copy/paste a text to Winedt, it shows perfect, but when I compile it to Pdf, some issues appear, e.g. finding becomes nding.

I am wondering if there is any way to search and find these characters?

Here is an example file (needs utf8 encoding).

\documentclass{article}
\begin{document}
fi
\end{document}
Ian Thompson
  • 43,767
NESHOM
  • 697
  • To be clear, are you saying that you copy 'finding' from a pdf into winedt and it displays ok, but problems occur when you compile the resulting code? If so, do you get any warnings in the log file? – Ian Thompson Jun 02 '14 at 12:38
  • I don't think that is a winedt problem, but your used font and its ability to use ligatures. Try to paste the characters in a plaintext-editor (like notepad) instead winedt, I bet there are no ligatures. – musicman Jun 02 '14 at 13:23
  • No, when I copy finding from word to latex, it won't appear correctly when it is compiled. I have to delete fi and type it again to fix it. I realise when this happens, fi is as one character and not two! So I'd like to know if there is anyway to search and find these characters in Winedt? (of course, nothing wrong with Win edt) – NESHOM Jun 02 '14 at 13:32
  • i assume you're talking about copying from a tex-sourced pdf, rather than a "tex file" (such as .tex or .dvi). if i'm right, i guess you need the cmap or mmap packages. [note, i'm not clear about the difference between those two, and would welcome enlightenment.] – wasteofspace Jun 02 '14 at 13:45
  • so no way to just find and remove them from tex file? – NESHOM Jun 02 '14 at 14:10
  • Are there any warnings about this in the log file? – Ian Thompson Jun 02 '14 at 14:22
  • it doesn't really matter from where I am copying the text, does it? some texts are like this when are copied to tex file! – NESHOM Jun 02 '14 at 14:23
  • what should I look in the log file? – NESHOM Jun 02 '14 at 14:26
  • How are the tex files being compiled: Straight to pdf, or first to dvi, then to ps, then to pdf? – Mico Jun 02 '14 at 14:34
  • I use pdflatex in winedt directly! – NESHOM Jun 02 '14 at 14:44
  • NO, when I copy/paste word "finding" from this page, it if just fine in the compiled pdf! I mean fi are two characters. In those problematic cases that I am referring to, fi is as one character. Maybe those are from a pdf file that is compiled somehow from latex! Is there any way to share a tex file here? – NESHOM Jun 02 '14 at 15:00
  • This isn't a duplicate of What are good ways to make pdflatex output copy-and-pasteable. The OP already has a pdf and is pasting from it into a LaTeX editor. – Ian Thompson Jun 02 '14 at 16:01
  • @M0HS3N --- if you add \usepackage[utf8]{inputenc} the ligatures will generate errors, which makes them easy to find (removing them will still be annoying if there are lots). – Ian Thompson Jun 02 '14 at 16:04
  • I think I have an answer now. I've asked other users to vote to reopen... – Ian Thompson Jun 02 '14 at 16:18

2 Answers2

8

This is commonly due to bad font information, but is solvable. The ligatures that can give problems are , if a modern font is used.

You can solve at once your problem with

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

%% use this in your preamble
\usepackage{newunicodechar}
\newunicodechar{ff}{ff}
\newunicodechar{fi}{fi}
\newunicodechar{fl}{fl}
\newunicodechar{ffi}{ffi}
\newunicodechar{ffl}{ffl}
%% end of common ligatures

\begin{document}
ff fi fl ffi ffl
\end{document}

The relevant code is between the two %% prefixed lines. Just keep it at hand and paste it when needed.

enter image description here

A “search and replace” can be better, for the production version of the document.

egreg
  • 1,121,712
0

If you add \usepackage[utf8]{inputenc} to your preamble, the ligatures in the code will generate errors. There may be a lot, but there are (I think) only a few distinct cases. With inputenc in your preamble, run pdflatex. It will stop on the first ligature, and entering 'e' should take you to it. Copy the ligature and do a global find and replace, e.g. changing to fi. Repeat for the other ligatures and the problem is solved. Not entirely automatic, but it shouldn't take too long.

Ian Thompson
  • 43,767