8

I would like to use Adobe Times Roman font or its equivalent (like URW Nimbus Roman and fonts based on it), compiling with pdflatex to PDF -- the original intent was to have PDF smaller by using built-in fonts. The document in question is in Polish, and uses UTF-8 input encoding. I would like the PDF to be copy-and-pasteable with result in UTF-8, for both roman family and typewriter family (for code listing).

Unfortunately neither of solutions in What are good ways to make pdflatex output copy-and-pasteable? works, at least not with \usepackage{times} as a way to switch to Roman-like font.

Take an example document:

\documentclass{article}

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

\usepackage{times}
%\usepackage{lmodern}

\input glyphtounicode
\pdfgentounicode=1
%\usepackage{cmap}

\begin{document}
\noindent
\rmfamily
rmfamily: zażółć gęsią jaźń \\
\ttfamily
ttfamily: zażółć gęsią jaźń \\
\end{document}

The result is not an unrecognizable mess of symbols as was in Can't copy-paste from my PDF. Any idea why?, but some of Polish characters are copied in a strange way, as if precomposed: with base character and accent (decoration) separate... and either of them can be out of text flow.

For the example document the pdftotext result (and copy'n'paste result) is:

˙ c e ˛ z´
rmfamily: zazół´ g˛ sia ja´ n
ttfamily: za˙ół´ g˛sia ja´´
z c e ˛
zn

1

If I switch from times to lmodern (Latin Modern font), and presumably also when switching to cm-super I get the correct result:

rmfamily: zażółć gęsią jaźń
ttfamily: zażółć gęsią jaźń

1
6
  • 1
    First time I've seen this without the brackets around glyphtounicode. AFAIK it's a file and thus it should be {glyphtounicode}.
    – henry
    Apr 17, 2015 at 18:40
  • 1
    @henry If I use \input{glyphtounicode}, my code below won't work anymore. The copy-and-past will be gobbled.
    – Sverre
    Apr 17, 2015 at 18:55
  • @Sverre ... woah. That is the first time I read of this happening so either something is not working right and/or I am way out of my depth here. Seeing how you and egreg talking about this, the latter is certainly true.
    – henry
    Apr 18, 2015 at 8:23
  • 1
    @henry I'm as puzzled as you are. This hasn't made a difference for me before, but for some reason it does here. I might open a separate question about it.
    – Sverre
    Apr 18, 2015 at 12:40
  • 1
    Btw: It's 2015 and we have XeTeX and LuaTeX: No need to use pdfTeX with Unicode anymore, use engines that support Unicode directly. Apr 21, 2015 at 19:24

2 Answers 2

6

You can use the Times font TeX Gyre Termes:

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

\input glyphtounicode
\pdfgentounicode=1

\begin{document}
\noindent
\rmfamily
rmfamily: zażółć gęsią jaźń \\
\ttfamily
ttfamily: zażółć gęsią jaźń \\
\end{document}

enter image description here

Copy and paste from the .pdf gives this result:

rmfamily: zażółć gęsią jaźń
ttfamily: zażółć gęsią jaźń
2
  • Or newtxtext and the accompanying newtxmath for math symbols.
    – egreg
    Apr 17, 2015 at 18:38
  • @egreg If I use newtxtext, I get this when I copy-and-paste from the .pdf: zażółć g˛esi˛a jaźń. It doesn't cope with the ogonek glyphs, in other words.
    – Sverre
    Apr 17, 2015 at 18:49
0

Adding to Sverre's answer of using TeX Gyre Termes (tgtermes package): it doesn't work for me with \ttfamily / \texttt{} i.e. typewriter fonts. I get the following from pdftotext (version 0.12.4):

rmfamily: zażółć gęsią jaźń
ttfamily: za»óª¢ g¦si¡ ja¹«

I have browsed The LaTeX Font Catalogue and found out the following solution -- use TXTT font for ttfamily with \renewcommand*\ttdefault{txtt}:

\documentclass{article}

\usepackage{tgtermes}
\renewcommand*\ttdefault{txtt}

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

\input glyphtounicode
\pdfgentounicode=1

\begin{document}
\noindent
\rmfamily
rmfamily: zażółć gęsią jaźń \\
\ttfamily
ttfamily: zażółć gęsią jaźń \\
\end{document}
3
  • 2
    You seem to be using an extremely old version of pdftotext, since the current version is 3.04. Running pdftotext -enc UTF-8 [PDF-file] on the output file of my code gives me rmfamily: zażółć gęsią jaźń ttfamily: zażółć gęsią jaźń.
    – Sverre
    Apr 18, 2015 at 15:03
  • @Sverre: When using evince 3.10.3 copy'n'paste gives me without TXTT: rmfamily: zażółć gęsią jaźń tt❢❛♠✐❧2✿ 3❛➺ó➟➣ ❣➛s✐→ ❥❛➵➠ Apr 18, 2015 at 15:08
  • 1
    Copy-and-paste from my output file with evince gives me rmfamily: zażółć gęsią jaźń ttfamily: zażółć gęsią jaźń. You may want to update your TeX packages or something.
    – Sverre
    Apr 18, 2015 at 15:17

You must log in to answer this question.

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