16

If I copy text to the clipboard from a PDF file, web page, email, or Word document and then paste it to Word or Thunderbird, it is recognized as rich text and converted to Word's or Thunderbird's native format. Does anyone know of a LaTeX GUI (editor) that can do the same?

For example, if I copy "Do this now!!!" from this webpage and paste it into my favorite LaTeX editor, it should become Do \emph{this} \textbf{now!!!}. But all the LaTeX editors I've ever tried will handle pastes as plain text.

Addendum: There's nothing technically difficult about accepting some rich text features from pastes. Applications put objects on the clipboard in multiple formats, and the receiving application can choose a format it can handle. Any editor could request HTML and map all sorts of structured mark-up to LaTeX, from bold or centering to hyperlinks, to section headings and table structure, etc. Is there really no LaTeX editor that goes to the trouble?

alexis
  • 7,961
  • One should be aware that, if there are any, they will probably have difficulty with tables and images and so on. – cyberSingularity Dec 17 '12 at 13:43
  • Images, certainly. But tables are unambiguously marked in html, so there's no reason not to turn them into a LaTeX table on pasting. And the clipboard protocol can negotiate HTML format even from Word; it's not like the editor needs to parse raw PDF or whatever. (This is also no reason not to do the really trivial stuff) – alexis Dec 17 '12 at 13:46
  • See pandoc for an alternative solution. – yannisl Dec 17 '12 at 13:47
  • @alexis: Okay, yes, so one should perhaps expect the same limitations as HTML to LaTeX converters. Taking tables again, they can be quite complicated, with border styles, cells spanning multiple rows/columns etc. And even font selection may be problematic, depending on which engine the editor assumes is used. One should not expect good semantic output in all situations (eg \texttt). – cyberSingularity Dec 17 '12 at 13:50
  • Agreed. It's not even desirable to import a mish-mash of fonts into a LaTeX document. I'm not asking for fully automated conversion, though, or for the spitting image. If you copy and paste a table, would you rather get a table without styles and borders, or just the cell contents in an ugly pile? – alexis Dec 17 '12 at 13:57
  • @Yianni, using a separate application for the conversion is fine for heavy-duty use, but it's no solution if I just want to grab and edit a bit of text: I must copy it, paste it into Word, save it as HTML, run it through Pandoc, and finally open it in my favorite LaTeX editor. – alexis Dec 17 '12 at 14:04
  • 1
    This would be great. Even if all you had was text formatting (i.e., bold, italics, etc.) that would be useful for the back and forth that so often happens when editing or revising a document. –  Dec 19 '12 at 11:21
  • 1
    The table models of html and latex are very different and it is a complicated (and historically error prone) conversion. It is better to make tricky conversions part of an explicit conversion step rather than automatically on paste. I think you have the clipboard model backwards: It is up the pasting application to provide a range of formats. It has more information about the structure of the text and could put latex on the clipboard as one of the formats. That would be more reliable than the pasting application making html or rtf and the latex editor having to guess equivalent latex markup – David Carlisle Dec 19 '12 at 17:27
  • 1
    If you want to have this property then you can use LyX and probably use a converter http://rtf2latex2e.sourceforge.net/index.html but otherwise you need to see why people don't implement this. – percusse Dec 19 '12 at 17:27

1 Answers1

6

LaTeX is build upon ASCII. What you are asking is a feature of the WYSIWYG world converted into the ASCII world.

But the ASCII world decided for another approach: There are converters from WYSIWYG to LaTeX. One mighty software is LibreOffice and its addon "writer2latex". You can throw RTF, *.doc or whatever into the writer and export it as LaTeX. If Libreoffice is not capable enough, because the RTF-file uses features not supported by the writer, then you are in trouble. But for italics and the like, this is the easiest way.


Edit 1.

OP comments (see below):

Keks, I am asking for nothing of the sort. I am asking for a standard feature of the GUI world that is sadly missing from LaTeX GUIs. I don't want bold text to look bold in my editor-- but it should become \textbf{text}.

I understand that. But what you ask for is exactly that kind of background changes people very often hate. They copy text from somewhere and don't want the software to imitate sense by providing whatever layout feature. They just want the text. And if they need more, they go for the converter.

One of the best feature of editors is not to behave like Word!

Keks Dose
  • 30,892
  • Keks, I am asking for nothing of the sort. I am asking for a standard feature of the GUI world that is sadly missing from LaTeX GUIs. I don't want bold text to look bold in my editor-- but it should become \textbf{text}. Converters are stand-alone tools, on par with using latex and pdflatex from the command line. A GUI is a GUI, and accepting pastes is a standard (and simple) feature. – alexis Dec 19 '12 at 15:48
  • @alexis This requires knowing how the operating system manages copying and pasting with formatting instructions. It might use RTF so making what you want at least possible; but the editor should know about how the call to different fonts is implemented. I wouldn't even try thinking to implement it. – egreg Dec 19 '12 at 15:58
  • 1
    @egreg, I don't know your background, but it's really not that hard. The OS doesn't control the format of the rich text. The application makes the text available in multiple formats (typically including plain text), and the application on the receiving end chooses looks for a format it can handle. It's all handled by the clipboard API. Compared to integrating a GUI app with the OS-supplied widgets and window manager(s), it's trivial. – alexis Dec 19 '12 at 16:05
  • @alexis Well, RTF uses explicit font changes, IIRC; so how's the TeX front end supposed to react to "choose Times New Roman Italic"? – egreg Dec 19 '12 at 16:08
  • TBH I wouldn't want it to import the font name: Nobody wants a mish-mash of font sizes and faces in my text (that is, indeed, the Word way and we reject it :-). But there's a host of features that it makes sense to keep, and I've listed some of them. Bold, of course, but also sub/superscripts, tables, section headers, ... – alexis Dec 19 '12 at 16:11
  • 1
    @alexis I am 100% sure that there's no such editor. And especially after your comments and explanations here, it seems to me that this is a question for WinAPI/Xserver/... programmers, not for people who do TeX programming. From a LaTeX point of view the situation is clear, you can either use grouping command \textbf{text} or switching commands \bfseries text \mdseries, but I suppose you know this. – yo' Dec 19 '12 at 20:10