Is it possible to change export template?

156 views
Skip to first unread message

Vidyut

unread,
Jul 6, 2020, 5:24:09 AM7/6/20
to ywr...@googlegroups.com
I am wondering if it is possible to change the exported content using some kind of a template. For example, if I want to start a chapter or scene with a POV, location or time and so on or format the chapter titles with h2 and add scene titles with h3, etc in the html export of the book.

Peter T.

unread,
Jul 7, 2020, 3:25:43 AM7/7/20
to yWriter
Excellent idea, Vidyut. In this way, not only novel exports, but also customized reports of all kinds, even tables, can be generated. 
I'm now writing a Python script that runs through all chapters and scenes and fills HTML templates. I'll get back when it's ready for use.

Cheers, 
Peter

Simon Haynes

unread,
Jul 7, 2020, 5:49:31 AM7/7/20
to ywr...@googlegroups.com
It's possible to create a project.css file in the main project folder, and when exporting to ebook the css in this file will override the yWriter defaults. (No need to edit the intermediate html file)

Sample file attached so you can modify it and use the results. You should be able to change/add anything which is recognised by Calibre.

This was something I created for my own use so I don't think I documented it.

Remember that setting the font typeface won't alter what the user sees on their ebook reader though.

On Mon, 6 Jul 2020 at 17:24, Vidyut <wide....@gmail.com> wrote:
I am wondering if it is possible to change the exported content using some kind of a template. For example, if I want to start a chapter or scene with a POV, location or time and so on or format the chapter titles with h2 and add scene titles with h3, etc in the html export of the book.

--
You received this message because you are subscribed to the Google Groups "yWriter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ywriter+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ywriter/CA%2BJcQHhSpJO-JQbmxfLciqdmDTyjBo%3D1_7Gqq9ZsRg8x%2BP7VGw%40mail.gmail.com.


--

--
Visit Spacejock Software, the home of yWriter, FCharts and more
Visit spacejock.com.au for my articles on writing and publishing novels.
project.css

Simon Haynes

unread,
Jul 7, 2020, 5:54:23 AM7/7/20
to ywr...@googlegroups.com
To create custom headings in your exported file ...

image.png



image.png

and ...

image.png




image.png

image.png


On Mon, 6 Jul 2020 at 17:24, Vidyut <wide....@gmail.com> wrote:
I am wondering if it is possible to change the exported content using some kind of a template. For example, if I want to start a chapter or scene with a POV, location or time and so on or format the chapter titles with h2 and add scene titles with h3, etc in the html export of the book.

--
You received this message because you are subscribed to the Google Groups "yWriter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ywriter+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ywriter/CA%2BJcQHhSpJO-JQbmxfLciqdmDTyjBo%3D1_7Gqq9ZsRg8x%2BP7VGw%40mail.gmail.com.

Vidyut

unread,
Jul 7, 2020, 9:59:00 AM7/7/20
to ywr...@googlegroups.com
This looks promising! Will experiment and see.

Simon Haynes

unread,
Jul 7, 2020, 10:02:38 AM7/7/20
to ywr...@googlegroups.com
I just added a 'Create project.css' button to the Ebook tab on the Project Settings form. It'll write out the default file into the current project folder so people can experiment.

To revert to the default, just delete the project.css file and export the ebook again.

Also the screenshots I pasted show examples of project variables. You can also set up global variables which are per-machine (all projects), rather than per project.  However, a project variable will override a global variable with the same name.

Cheers
Simon

On Tue, 7 Jul 2020 at 21:58, Vidyut <wide....@gmail.com> wrote:
This looks promising! Will experiment and see.

--
You received this message because you are subscribed to the Google Groups "yWriter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ywriter+u...@googlegroups.com.

Vidyut

unread,
Jul 7, 2020, 10:41:39 AM7/7/20
to ywr...@googlegroups.com
Yes, I understood the global variables and project variables. It is a sort of workaround. Though what I was asking for was at export. Either as settings that can be selected in the export tab, or a template that can be edited to add information about the scene being exported. For example, for an export to check for problems in continuity, I may export with the date and time, or need POV character names before each scene - which may not be present in the final book export, so editing each chapter to add variables to the text isn't really the solution I was seeking. Besides, these are already things added to the scene, so editing each chapter to add manually doesn't make a sense for the purpose I was seeking, though some of it may be solved through manually adding global variables.

Simon Haynes

unread,
Jul 7, 2020, 12:58:38 PM7/7/20
to ywr...@googlegroups.com
Have you checked some of the project, chapter and scene reports? One of those includes everything (pov, titles, notes, etc)

On Tue, 7 Jul 2020 at 22:41, Vidyut <wide....@gmail.com> wrote:
Yes, I understood the global variables and project variables. It is a sort of workaround. Though what I was asking for was at export. Either as settings that can be selected in the export tab, or a template that can be edited to add information about the scene being exported. For example, for an export to check for problems in continuity, I may export with the date and time, or need POV character names before each scene - which may not be present in the final book export, so editing each chapter to add variables to the text isn't really the solution I was seeking. Besides, these are already things added to the scene, so editing each chapter to add manually doesn't make a sense for the purpose I was seeking, though some of it may be solved through manually adding global variables.

--
You received this message because you are subscribed to the Google Groups "yWriter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ywriter+u...@googlegroups.com.

Peter T.

unread,
Jul 7, 2020, 4:48:17 PM7/7/20
to yWriter
The versatility of yWriter keeps amazing me.

I have now put together a script that uses templates to create an HTML file. The possibilities are extremely various. Below you can see two examples. On the left is the browser display, on the right the HTML templates in the editor.

First example: A manuscript with the viewpoint displayed at the top of each scene.

manuscript.png


Second example: A scene list with randomly selected items.

table.png


I still have to refine everything a bit and tie it into a package. Then you can download it from my GitHub repository.

Cheers, 
Peter

Vidyut

unread,
Jul 7, 2020, 5:29:49 PM7/7/20
to ywr...@googlegroups.com
Many useful ideas. Thanks Simon, Peter.

Looking forward to your GitHub share, Peter! 

V

DarthNewton

unread,
Jul 8, 2020, 9:30:01 PM7/8/20
to ywr...@googlegroups.com
You can do this already. Well perhaps not with a template system built in but H3 scene titles yes. Create a "title scene" and start it like this:
<html>
Then put all your HTML after it. Like <center>Scene 1</center> for example. The <html> on the first line tells yWriter how to handle the scene when you export it. It works the same way with LaTex as well just put <TEX> on the first line by itself instead of <HTML> :)

I find I use a special scene for just these titles/codes, this way I only have to use the HTML/LaTex in a few scenes rather than every one and let yWriter export them as usual.

Also you can set these different scenes to only export when doing HTML, RTF, LaTex, etc so they don't show up everywhere. For example your HTML coded scene doesn't pop up in your LaTex export.

This gives a lot of flexibility and I have used it a lot to get my ebooks or print books formated like I want with a minimal amount of editing after yWriter. :) The only 'trick' is you need to know the html or LaTex commands to use. And once you get one set up like you want, you can reuse it, editing little bits where needed copying them from book to book.

Peter T.

unread,
Jul 9, 2020, 2:57:24 PM7/9/20
to yWriter
A beta test release of the yWriter to HTML converter with templates is now available: 

Please make sure Python 3.4 (or more recent) is installed on your system. You can get it for free here: https://www.python.org/

In this version, the script is started from the command line or a batch file. 
Note: Placeholders for date/time are yet to be implemented.

The latest idea:
You can also design the "html templates" in a tricky way to create csv output for loading into spreadsheet programs like Excel or OpenOffice Calc. Here is an example: 

csv.png


Regards, 
Peter

Vidyut

unread,
Jul 10, 2020, 2:29:01 AM7/10/20
to ywr...@googlegroups.com
wow. Just having the templates itself was a dramatic help. I wasn't sure of syntax, placeholders available, structure of templates, etc. 

Vidyut

unread,
Jul 10, 2020, 2:30:34 AM7/10/20
to ywr...@googlegroups.com
My goal with this query is largely met now. Will implement the placeholders for date once they become available, but everything else is doable right now. This is more than "good enough".

Time to get back to the writing. Thanks a ton, everyone.

Peter T.

unread,
Jul 10, 2020, 5:57:00 AM7/10/20
to yWriter
Placeholders available are listed in the README file.
I will now have a look at the date/time information stored in the yWriter projects. Then I intend to add some more template examples such as synopses of varying scope, lists of scene notes etc.

Although my script is an HTML converter, you can use it to produce other text formats (as the csv example shows). If necessary, simply replace the html tags in the "SceneContent" etc. output with other formatting instructions in a text editor. Or use a tool to strip html tags completely. Then rename the output file. Or just use Pandoc to convert the html file into another format. 

Peter T.

unread,
Jul 10, 2020, 8:38:52 AM7/10/20
to yWriter
Vidyut, 

now version 0.2.0 with date/time placeholders is ready: https://github.com/peter88213/yw2html

Here is an example that might come near to your wishes: 

thriller.png


As announced, I added more sample templates, for example this one for "plotting": 

plot.png


Have fun!
Peter

Vidyut

unread,
Jul 10, 2020, 4:25:59 PM7/10/20
to ywr...@googlegroups.com
Wow. You guys are like the wish fulfilling fairy! <3

This is super.

V

--
You received this message because you are subscribed to the Google Groups "yWriter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ywriter+u...@googlegroups.com.

Peter T.

unread,
Jul 11, 2020, 8:02:36 AM7/11/20
to yWriter
Glad to hear that, Vidyut.

Basically, yWriter already offers a lot of reports and exports, but if you like it special and know HTML, CSS and CSV, nearly everything is feasible with scripting. 
However, for a writer, creating tools like that is a kind of procrastination, isn't it? I had a writer's block to overcome, but I shall soon return to writing.

Another thing: In the latest version 0.3.0 you can now export customized character, location and item reports. For example, a character list like this: 

charlist.png


Cheers, 
Peter

Vidyut

unread,
Jul 29, 2020, 2:43:37 PM7/29/20
to ywr...@googlegroups.com
Peter, finally got around to using the export script. Pardon me if I am missing something obvious - I have no experience with python.

I am using yWriter on a Ubuntu laptop through WINE - this may be the source of some of the problems possibly.

Firstly, the script doesnt run on Ubuntu off the bat. I had to convert it using a utility called dos2unix with sudo apt-get install dos2unix and then dos2unix yw2html.pyw

Then I had to add #!/usr/bin/env python3 at the start of the file.

Then I realized I didn't have tkinter, so sudo apt-get install python3-tk

The file now appears to run, but still doesn't export. Traceback:

Traceback (most recent call last):
  File "./yw2html.pyw", line 2939, in <module>
    run(args.sourcePath, templatePath, suffix, silentMode)
  File "./yw2html.pyw", line 2894, in run
    converter = YwCnvGui(sourcePath, document, silentMode)
  File "./yw2html.pyw", line 2186, in __init__
    self.convert(sourcePath, document)
  File "./yw2html.pyw", line 2228, in convert
    text=self.yw_to_document(ywFile, document))
  File "./yw2html.pyw", line 2061, in yw_to_document
    message = ywFile.read()
  File "./yw2html.pyw", line 853, in read
    self.scenes[scId].time = dateTime[1]
IndexError: list index out of range

Now what?


Peter T.

unread,
Jul 29, 2020, 5:29:36 PM7/29/20
to yWriter
Congratulations, Vidyut. Basically, the script wasn't intended for another OS than Windows. So you did quite a good job to make it run on Linux. The dos2unix tool seems to replace Windows line breaks with Unix line breaks. The  #!/usr/bin/env python3  line is needed if you call the Python script directly from the command line, because Unix/Linux doesn't assign  applications to file extensions like DOS/Windows does. So scripts have to include some information about the interpreter on which it's to run.

Another possibility is to launch the Python script by a shell script specifying the Python interpreter, your project path, and your preferred settings, like this:

#! /bin/sh
/usr/bin/env python3 ./yw2html.pyw /user/ywpath/myproject.yw7 -t ./manuscript -s _manuscript

The Traceback says that at least one of your yWriter scenes has a date, but no time saved. (dateTime[0] is the date, dateTime[1] is the time which is missing in this case). I had not considered this possibility, because yWriter auto-fills the time field with "00:00"  if you set a date but no time. But don't worry, it's easy to cover that.

I've now released v0.5.2.also prepared for Linux use. You don't need dos2unix any more, and the shebang is included now. 
Since I made this release "on the fly", I haven't tested it thoroughly. Apart from that I have no Linux available at the moment. Please try it out and give me a short feedback. 
Download page:

Cheers, 
Peter

Vidyut

unread,
Jul 29, 2020, 5:51:39 PM7/29/20
to ywr...@googlegroups.com
Worked so perfectly that for a moment I was confused that there was nothing else to do!

Simply brilliant. Solves all my problems.

Thank you!!!!!!!

Vidyut
Social Media: Twitter Facebook Google+ Diaspora


--
You received this message because you are subscribed to the Google Groups "yWriter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ywriter+u...@googlegroups.com.

Vidyut

unread,
Jul 29, 2020, 6:27:09 PM7/29/20
to ywr...@googlegroups.com

It is possible to set file extension associations in Ubuntu - I do it with the yWriter files, but frankly, it is just simpler to do this from the terminal, as the file needs parameters. It doesn't make sense to make many launcher icons with different projects and/or parameters and keep track of all of them. Though now that you mention it, may be a good idea to create a launcher for the most used export command.

Since you are making this Linux friendly as well, if I decide to do this, do you want a copy of the .desktop file to include? My way of giving back. (people will need to edit the paths/parameters in it to reflect their locations, though). If they move it to /usr/share/applications, they should be able to pin it to the favorites on the dashboard as well.

Vidyut

unread,
Jul 29, 2020, 6:50:19 PM7/29/20
to ywr...@googlegroups.com
For desktop launcher that works on Ubuntu, in a text file called export-yWriter.desktop (name does not matter, extension has to be .desktop), added the following lines.

[Desktop Entry]
Name=Export Symbiosis
Exec=bash -c "env python3 /path/to/yw2html/yw2html.pyw -t /path/to/yw2html/template-dir /path/to/yWriter/Project.yw7"
Type=Application
Icon=ywriter 

For the launcher to work, the paths will have to be correct and the file should have permissions to execute (right click > properties > permissions > executable). The parameters for the command can be edited to taste. It will launch from any folder/desktop the launcher is in as long as the paths and permissions are correct. To appear in applications search (because who wants to click around and browse to a folder to launch an icon?) and to be able to pin it to favorites on the dash, the file will have to be moved/copied to /usr/share/applications - this requires root privileges.

I am using the yWriter icon because I am lazy, but if there is a better icon, it can be set in the file as well.

V

Vidyut

unread,
Jul 29, 2020, 6:55:36 PM7/29/20
to ywr...@googlegroups.com
Sorry for multiple emails. Figured it was simpler to attach the .desktop file.
yw2html.desktop

Peter T.

unread,
Jul 30, 2020, 6:46:59 AM7/30/20
to yWriter
Thank you for the information, Vidyut. As far as I understand it, your desktop configuration file is an equivalent to the Windows Explorer file link. It may be not a Linux feature but a desktop feature that depends in detail on the desktop you are using (GTK, KDE, Mate, Unity, Cinnamon, XFCE and so on). Since I don't use any of these, I better not provide any configurations which may raise new questions by Linux users. 

By the way, on Windows I add context menu entries via the registry, extending e.g. the .yw7 context by my Python file converters. This is how it looks like in Windows Explorer:

Unbenannt.PNG


I'm quite sure your Linux desktop allows something similar.

There's an other way to comfortably launch scripts on Windows: if you drag and drop a yWriter project icon on a batch file, the project file path is passed as parameter to the batch file. The batch file itself is launched in the directory in which it's located. The yw2html zipfile includes some example batch files illustrating this. I guess, this might work with shell scripts on the Linux desktop in a similar way. Just explore it. 

Cheers, 
Peter

Peter T.

unread,
Jul 30, 2020, 8:11:28 AM7/30/20
to yWriter

Peter T.

unread,
Jul 30, 2020, 8:36:28 AM7/30/20
to yWriter
P.P.S.

Vidyut, if you want to share your yWriter/Linux experience, your tools and your configuration files, you might wish to have a look at GitHub. A free GitHub repository can also provide a Wiki for tutorials etc.
You even can adapt (if necessary) and offer my Python scripts according to the liberal MIT license I use (though it might become a problem to keep a "fork" up to date, especially if you don't program in Python).

But be warned: yWriter is designed to save time for authors, so experience shows that there are very few users who want to run a "construction site" around it. 

Vidyut

unread,
Jul 30, 2020, 11:28:51 AM7/30/20
to ywr...@googlegroups.com
It has been a long time since I've used Windows. I barely remember anything.

I had considered writing a simple post explaining use of yWriter on Ubuntu. I may do that at some point and add this to it as suggestions.

Right now there doesn't seem to be a problem to fix. The terminal works well for me. No one else needs that functionality so far.

I should get back to writing the book first :D

Many thanks for your script. It has worked very well for my needs.

V

Simon Haynes

unread,
Jul 30, 2020, 11:32:38 AM7/30/20
to ywr...@googlegroups.com
There's a page on my site re running yWriter on Ubuntu, Debian and other variants, but it goes out of date fairly often.

What I should do is build a deb file or something with the prerequisites.


--
You received this message because you are subscribed to the Google Groups "yWriter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ywriter+u...@googlegroups.com.

Peter T.

unread,
Jul 30, 2020, 11:44:06 AM7/30/20
to yWriter
That's what we all want to do ...

Good luck!

Peter T.

unread,
Jun 29, 2021, 4:39:42 AM6/29/21
to yWriter
In the meantime, some experience has been gained with the yw2html script.  In addition, I have continuously extended its capabilities, so it might be worthwhile for users to download the latest version.

It offers e.g. the possibility to decorate chapter headings with vignettes via the HTML <img> tag. 

screenshot.png

A rather sophisticated example of how to prepare a paperback layout using yw2html can now be found in this thread: 

Cheers, 
Peter
Reply all
Reply to author
Forward
0 new messages