Discussion:
copying LaTeX text into a LyX document from clipboard
David Soukal
2005-09-04 17:08:34 UTC
Permalink
Hello,

I was wondering whether it is possible to paste a well-formated fragment
of LaTeX code from clipboard into an open document in such a way that
LyX interprets the LaTeX code being inserted? The standard "paste"
command will, of course, treat the content as a regular piece of text,
but I'd like to paste the text interpreted.

I realize it's possible to import the whole document and then copy the
fragments from the LyX, but it would come in handy to have the option to
paste only pieces of LaTeX code without having to do anything else.

Thanks for any hints.

David

ps. The reason why I'm asking this is that I'm importing a LaTeX
document from a co-author of our paper. He defined simple command \fp{}
which is a synonym for \textcolor{red}{}. The author did that for two
purposes: 1) to save some keystrokes :), and 2) to mark the portions of
text that were updated by him.

While LyX imports the document fine, it doesn't interpret the \fp{}
command but inserts the \fp{} blocks as ERT boxes which makes half of
the document uninterpreted and very hardly editable.
Angus Leeming
2005-09-04 17:42:01 UTC
Permalink
Post by David Soukal
Hello,
I was wondering whether it is possible to paste a well-formated fragment
of LaTeX code from clipboard into an open document in such a way that
LyX interprets the LaTeX code being inserted? The standard "paste"
command will, of course, treat the content as a regular piece of text,
but I'd like to paste the text interpreted.
I realize it's possible to import the whole document and then copy the
fragments from the LyX, but it would come in handy to have the option to
paste only pieces of LaTeX code without having to do anything else.
Thanks for any hints.
David
You can do this for mathed but not for the rest of LyX. Eg, typing as
normal text "$a=b+c$" (without quotes), highlighting the block and
selecting Insert->Math->Display Formula will convert the code into a
mathed inset.
Post by David Soukal
ps. The reason why I'm asking this is that I'm importing a LaTeX
document from a co-author of our paper. He defined simple command \fp{}
which is a synonym for \textcolor{red}{}. The author did that for two
purposes: 1) to save some keystrokes :), and 2) to mark the portions of
text that were updated by him.
While LyX imports the document fine, it doesn't interpret the \fp{}
command but inserts the \fp{} blocks as ERT boxes which makes half of
the document uninterpreted and very hardly editable.
If LyX interprets \textcolor{red}{} as you'd like, why not add a
pre-processor step to your conversion. Something like (untested):

$ sed 's/\\fp{}/\\textcolor{red}{}/g' input.tex > output.tex
$ diff -u input.tex output.tex
--
Angus
David Soukal
2005-09-04 22:09:48 UTC
Permalink
Post by Angus Leeming
You can do this for mathed but not for the rest of LyX. Eg, typing as
normal text "$a=b+c$" (without quotes), highlighting the block and
selecting Insert->Math->Display Formula will convert the code into a
mathed inset.
Still it would be great, if it were possible to do that with any text.
Since the functionality is there already for the import... I try to put
a feature request...
Post by Angus Leeming
If LyX interprets \textcolor{red}{} as you'd like, why not add a
$ sed 's/\\fp{}/\\textcolor{red}{}/g' input.tex > output.tex
$ diff -u input.tex output.tex
Unfortunatelly, LyX does not do that. I was very surprised since color
text gets exported to LaTeX as \textcolor{} but the import does not
work. It gets imported as two ERT boxes: one with \textcolor{red}{ and
the other with the closing brace }.

Thank you,

David
Angus Leeming
2005-09-05 07:24:29 UTC
Permalink
Post by David Soukal
Unfortunatelly, LyX does not do that. I was very surprised since color
text gets exported to LaTeX as \textcolor{} but the import does not
work. It gets imported as two ERT boxes: one with \textcolor{red}{ and
the other with the closing brace }.
I take it that you're using the reLyX perl script to convert TeX to LyX?
Try out the newer and much more powerful tex2lyx:

http://wiki.lyx.org/LaTeX/LatexToLyx
--
Angus
Andre Poenitz
2005-09-05 06:17:59 UTC
Permalink
Post by David Soukal
Post by Angus Leeming
You can do this for mathed but not for the rest of LyX. Eg, typing as
normal text "$a=b+c$" (without quotes), highlighting the block and
selecting Insert->Math->Display Formula will convert the code into a
mathed inset.
Still it would be great, if it were possible to do that with any text.
Since the functionality is there already for the import... I try to put
a feature request...
On of the reason that it doesn't work (apart from nobody having
implemented it) is that a chunk of LaTeX does not carry all needed
informations like document class. So while it might be possible (and
certainly useful) to have such feature it never will work reliably in
all cases.

Anyway, create an entry on bugzilla if you don't want to get this lost.

Andre'

Loading...