Re: is it possible to create a lyx file as flat ASCII file?

2014-05-15 Thread Thirsty Camel
Sooo ... the answer is: yes it is possible

I just had no idea how sensitive LyX is for whitespace when loading a file.
I found an extra space at the end of a sentence can create the wobble of
not loading the document settings properly. Anyway, the python script below
works for me - it loads all the .eps files in a folder and creates a lyx
file that can be imported as an appendix.
For me this is a roundabout way to add multipage pdf files (reports) to the
document. First export the pdf to 1 page eps files. Then run this script
and add to the main document. If someone knows a more elegant way -
suggestions are welcome.

Cheers



import glob, os



"""

  Use: python lyx_eps_appendix.py > MyLyxFile.lyx

"""





def main():

removeSpace(r'*.eps')

lyxHeader()

lyxGraphic(r'*.eps')

print '\n\n\end_layout\n\n\end_body\n\end_document'





def removeSpace(pattern):

for filename in glob.glob(pattern):



os.rename(filename, filename.replace(" ", "0"))



def lyxGraphic(pattern):

for filename in sorted(glob.glob(pattern)):

bodypart1 = '\\begin_inset Graphics\n\tfilename '

bodypart2 = filename

bodypart3 = '\n\tdisplay false\n\twidth 12cm\n\n\\end_inset\n\n\n'

bodypart4 = '\\begin_inset Newpage clearpage\n\\end_inset\n\n'

lyxbody = bodypart1 + bodypart2 + bodypart3 + bodypart4

print lyxbody



def lyxHeader():

print '#LyX 2.0 created this file. For more info see
http://www.lyx.org/\n\\lyxformat 
413\n\\begin_document\n\\begin_header\n\\textclass
article\n\\use_default_options true\n\\maintain_unincluded_children
false\n\\language english\n\\language_package default\n\\inputencoding
auto\n\\fontencoding global\n\\font_roman default\n\\font_sans
default\n\\font_typewriter default\n\\font_default_family
default\n\\use_non_tex_fonts false\n\\font_sc false\n\\font_osf
false\n\\font_sf_scale 100\n\\font_tt_scale 100\n\n\\graphics
default\n\\default_output_format default\n\\output_sync 0\n\\bibtex_command
default\n\\index_command default\n\\paperfontsize default\n\\use_hyperref
false\n\\papersize default\n\\use_geometry false\n\\use_amsmath
1\n\\use_esint 1\n\\use_mhchem 1\n\\use_mathdots 1\n\\cite_engine
basic\n\\use_bibtopic false\n\\use_indices false\n\\paperorientation
portrait\n\\suppress_date false\n\\use_refstyle 1\n\\index
Index\n\\shortcut idx\n\\color #008000\n\\end_index\n\\secnumdepth
3\n\\tocdepth 3\n\\paragraph_separation indent\n\\paragraph_indentation
default\n\\quotes_language english\n\\papercolumns 1\n\\papersides
1\n\\paperpagestyle default\n\\tracking_changes false\n\\output_changes
false\n\\html_math_output 0\n\\html_css_as_file 0\n\\html_be_strict
false\n\\end_header\n\n\\begin_body\n\n\\begin_layout Standard'











if __name__ == "__main__":

main()






2014-05-10 19:18 GMT-03:00 Thirsty Camel :

> Hey, that is new for me. Thanks a lot, I will have a look
>
> Still, if anyone can tell me if the lyx-file format has any hidden data or
> quirks that would be most welcome. If I know I can create lyx files without
> using lyx (e.g. emacs or python), that would be very useful.
>
> Many thanks
>
>
>
>
> 2014-05-10 17:30 GMT-03:00 Stephan Witt :
>
> Am 10.05.2014 um 17:35 schrieb Thirsty Camel :
>>
>> > Nope, I would not like to export
>> >
>> > What I would like is:
>> > 1. create a plain text file (*.lyx)
>> > 2. import into main document
>> >
>> > One step more: ideally I would like to use a script to select all
>> figures in a folder and create a lyx file that can be imported into the
>> main document.
>>
>> LyX is scriptable. But you need a running instance.
>>
>> See the chapter about the LyX Server in the Additional Manual.
>>
>> Perhaps this is helpful to solve your task.
>>
>> Stephan
>>
>> > 2014-05-10 5:09 GMT-03:00 Stephan Witt :
>> > Am 10.05.2014 um 02:36 schrieb Thirsty Camel :
>> >
>> > > Hmm, I spent quite a lot of time doing that without much success even
>> with very simple files. Is there anyone who has working tried and made it
>> work?
>> > >
>> > > Is it necessary to copy the complete header of lyx files - is there a
>> minimum header and footer?
>> >
>> > Is "Export => Simple Text" what you want?
>>
>>
>


Re: is it possible to create a lyx file as flat ASCII file?

2014-05-12 Thread José Matos
On Friday 09 May 2014 20:28:38 Thirsty Camel wrote:
> Is it possible to create a lyx file as pure ascii text, particularly a
> chapter?

Yes, I did that for my PhD thesis.

> I have been trying to create appendix files that should be imported into
> the main document. I would like to use a script to create my appendix files
> with 30-100 figures each instead of doing all this manually.

That was my case.

> Unfortunately
> I cannot seem to create a lyx file that is accepted by the main document,
> even if it looks to be 100% the same as a manual file. Is there some
> invisible text generated by lyx?

No invisible text or any other data other than the text available at the file.

> Many thanks for any help

-- 
José Abílio


Re: is it possible to create a lyx file as flat ASCII file?

2014-05-12 Thread Guenter Milde
On 2014-05-10, Thirsty Camel wrote:

> [-- Type: text/plain, Encoding:  --]

> Hey, that is new for me. Thanks a lot, I will have a look

> Still, if anyone can tell me if the lyx-file format has any hidden data or
> quirks that would be most welcome. If I know I can create lyx files without
> using lyx (e.g. emacs or python), that would be very useful.

This is definitely possible, see the example below.

While testing, I found out a possible reason for your failure: in the
first run I forgot to use a raw string in Python (i.e. the prefix
operator r in r"hello ..."). Then, all backslashes (which are used
extensively in LyX's file format have to be escaped.

In Python you must write either

  "\\fontencoding"
  
or 

  r"\fontencoding"
  
Otherwise the \f is interpreted as form feed.


Hope this helps,

Günter



#!/usr/bin/env python
# -*- coding: utf8 -*-
# :Copyright: © 2014 Günter Milde.
# Released without warranty under the terms of the
# GNU General Public License (v. 2 or later)

outfile = open("test-out.lyx", "w")

outfile.write(r"""
#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass article
\use_default_options false
\maintain_unincluded_children false
\language british
\language_package default
\inputencoding utf8
\fontencoding global
\font_roman lmodern
\font_sans lmss
\font_typewriter lmtt
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100

\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref true
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder true
\pdf_colorlinks true
\pdf_backref section
\pdf_pdfusetitle true
\papersize a4paper
\use_geometry false
\use_amsmath 1
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 0
\index Stichwortverzeichnis
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
Hello world.
\end_layout

\end_body
\end_document
""")

outfile.close()
 



Re: is it possible to create a lyx file as flat ASCII file?

2014-05-10 Thread Thirsty Camel
Hey, that is new for me. Thanks a lot, I will have a look

Still, if anyone can tell me if the lyx-file format has any hidden data or
quirks that would be most welcome. If I know I can create lyx files without
using lyx (e.g. emacs or python), that would be very useful.

Many thanks




2014-05-10 17:30 GMT-03:00 Stephan Witt :

> Am 10.05.2014 um 17:35 schrieb Thirsty Camel :
>
> > Nope, I would not like to export
> >
> > What I would like is:
> > 1. create a plain text file (*.lyx)
> > 2. import into main document
> >
> > One step more: ideally I would like to use a script to select all
> figures in a folder and create a lyx file that can be imported into the
> main document.
>
> LyX is scriptable. But you need a running instance.
>
> See the chapter about the LyX Server in the Additional Manual.
>
> Perhaps this is helpful to solve your task.
>
> Stephan
>
> > 2014-05-10 5:09 GMT-03:00 Stephan Witt :
> > Am 10.05.2014 um 02:36 schrieb Thirsty Camel :
> >
> > > Hmm, I spent quite a lot of time doing that without much success even
> with very simple files. Is there anyone who has working tried and made it
> work?
> > >
> > > Is it necessary to copy the complete header of lyx files - is there a
> minimum header and footer?
> >
> > Is "Export => Simple Text" what you want?
>
>


Re: is it possible to create a lyx file as flat ASCII file?

2014-05-10 Thread Stephan Witt
Am 10.05.2014 um 17:35 schrieb Thirsty Camel :

> Nope, I would not like to export
> 
> What I would like is:
> 1. create a plain text file (*.lyx)
> 2. import into main document
> 
> One step more: ideally I would like to use a script to select all figures in 
> a folder and create a lyx file that can be imported into the main document.

LyX is scriptable. But you need a running instance.

See the chapter about the LyX Server in the Additional Manual.

Perhaps this is helpful to solve your task.

Stephan

> 2014-05-10 5:09 GMT-03:00 Stephan Witt :
> Am 10.05.2014 um 02:36 schrieb Thirsty Camel :
> 
> > Hmm, I spent quite a lot of time doing that without much success even with 
> > very simple files. Is there anyone who has working tried and made it work?
> >
> > Is it necessary to copy the complete header of lyx files - is there a 
> > minimum header and footer?
> 
> Is "Export => Simple Text" what you want?



Re: is it possible to create a lyx file as flat ASCII file?

2014-05-10 Thread Thirsty Camel
Nope, I would not like to export

What I would like is:
1. create a plain text file (*.lyx)
2. import into main document

One step more: ideally I would like to use a script to select all figures
in a folder and create a lyx file that can be imported into the main
document.


2014-05-10 5:09 GMT-03:00 Stephan Witt :

> Am 10.05.2014 um 02:36 schrieb Thirsty Camel :
>
> > Hmm, I spent quite a lot of time doing that without much success even
> with very simple files. Is there anyone who has working tried and made it
> work?
> >
> > Is it necessary to copy the complete header of lyx files - is there a
> minimum header and footer?
>
> Is "Export => Simple Text" what you want?
>
> Stephan
>
>


Re: is it possible to create a lyx file as flat ASCII file?

2014-05-10 Thread Guenter Milde
On 2014-05-10, Thirsty Camel wrote:
>
> Hmm, I spent quite a lot of time doing that without much success even with
> very simple files. Is there anyone who has working tried and made it work?
>
> Is it necessary to copy the complete header of lyx files - is there a
> minimum header and footer?

I don't know the absolute minimum, but I woudl use LyX to create a
template (empty document or some dummy content or to-be-customized
content) and then use this as a base for the script-generated LyX-file.

Günter



Re: is it possible to create a lyx file as flat ASCII file?

2014-05-10 Thread Stephan Witt
Am 10.05.2014 um 02:36 schrieb Thirsty Camel :

> Hmm, I spent quite a lot of time doing that without much success even with 
> very simple files. Is there anyone who has working tried and made it work?
> 
> Is it necessary to copy the complete header of lyx files - is there a minimum 
> header and footer?

Is "Export => Simple Text" what you want?

Stephan



Re: is it possible to create a lyx file as flat ASCII file?

2014-05-09 Thread Thirsty Camel
Hmm, I spent quite a lot of time doing that without much success even with
very simple files. Is there anyone who has working tried and made it work?

Is it necessary to copy the complete header of lyx files - is there a
minimum header and footer?


2014-05-09 20:44 GMT-03:00 Liviu Andronic :

> On Sat, May 10, 2014 at 1:28 AM, Thirsty Camel 
> wrote:
> > Is it possible to create a lyx file as pure ascii text, particularly a
> > chapter?
> >
> > I have been trying to create appendix files that should be imported into
> the
> > main document. I would like to use a script to create my appendix files
> with
> > 30-100 figures each instead of doing all this manually. Unfortunately I
> > cannot seem to create a lyx file that is accepted by the main document,
> even
> > if it looks to be 100% the same as a manual file. Is there some invisible
> > text generated by lyx?
> >
> I heard people were doing this. Have you checked the EOL characters in
> both documents? Make sure that they're the same in both the main .lyx
> file and the generated one.
>
> Liviu
>
>
> > Many thanks for any help
> >
> >
>
>
>
> --
> Do you know how to read?
> http://www.alienetworks.com/srtest.cfm
> http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
> Do you know how to write?
> http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
>


Re: is it possible to create a lyx file as flat ASCII file?

2014-05-09 Thread Liviu Andronic
On Sat, May 10, 2014 at 1:28 AM, Thirsty Camel  wrote:
> Is it possible to create a lyx file as pure ascii text, particularly a
> chapter?
>
> I have been trying to create appendix files that should be imported into the
> main document. I would like to use a script to create my appendix files with
> 30-100 figures each instead of doing all this manually. Unfortunately I
> cannot seem to create a lyx file that is accepted by the main document, even
> if it looks to be 100% the same as a manual file. Is there some invisible
> text generated by lyx?
>
I heard people were doing this. Have you checked the EOL characters in
both documents? Make sure that they're the same in both the main .lyx
file and the generated one.

Liviu


> Many thanks for any help
>
>



-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail


is it possible to create a lyx file as flat ASCII file?

2014-05-09 Thread Thirsty Camel
Is it possible to create a lyx file as pure ascii text, particularly a
chapter?

I have been trying to create appendix files that should be imported into
the main document. I would like to use a script to create my appendix files
with 30-100 figures each instead of doing all this manually. Unfortunately
I cannot seem to create a lyx file that is accepted by the main document,
even if it looks to be 100% the same as a manual file. Is there some
invisible text generated by lyx?

Many thanks for any help