trustin / sphinx-binary

Run Sphinx on Windows, Linux and OS X with a single-file standalone binary.
14 stars 10 forks source link

Is there any plan to support generate pdf file? #3

Closed hengyunabc closed 4 years ago

hengyunabc commented 5 years ago

sphinx command:

make latexpdf
trustin commented 5 years ago

Sorry for a late reply, @hengyunabc. To be honest, I do not have any experience with building PDF with Sphinx. What do you think about sending a pull request?

matthiaskraaz commented 4 years ago

Hi trustin, thx for this fine project.

It is only a matter of making the -M option available. The -M option is somewhat like the -b option. To create a PDF using the latexpdf builder, you call sphinx-build -M latexpdef .... Unlike the -b option, the -M option must be first!

Right now you are calling build_main. Instead you need to call main, which processes the -M option like this:

def main(argv: List[str] = sys.argv[1:]) -> int:
    sphinx.locale.setlocale(locale.LC_ALL, '')
    sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')

    if argv[:1] == ['-M']:
        return make_main(argv)
    else:
        return build_main(argv)

I am not sure whether it's a good idea to include the first two lines of main. Perhaps that interacts badly with your packaging. I don't know. Perhaps it would be even an improvement to set the Python locale from LC_ALL. Anyway, you are setting LC_ALL in your code...

Of course, you could just change the call of build_main to:

    if argv[:1] == ['-M']:
        return make_main(argv)
    else:
        return build_main(argv)

and leave out the other lines of main.

If you create a Windows binary, I'd happily test it.

matthiaskraaz commented 4 years ago

BTW: -M enables the "make mode", which - apart from offering latexpdf and info as additional builders - speeds up rebuild significantly by just writing the outputs for changed input files. So it is a good thing for all builders including html. Gradle and Maven incremental build doesn't make much sense, if sphinx processes everything....

trustin commented 4 years ago

Thanks for the detailed report. I've just pushed a few commits and -M option indeed seems to work as expected. However, it has a known issue: https://github.com/sphinx-doc/sphinx/issues/4900 so I guess I can't enable it by default in my Maven/Gradle plugins.

trustin commented 4 years ago

Fixed in 0.8.1

matthiaskraaz commented 4 years ago

Great news! I tried it immediately and it works great!

Actually, I tried your Gradle plugin first, but resorted to using sphinx-binary directly (great modular design, BTW), because I am using

which are both not supported by the Gradle plugin. I didn't like to bother you with multiple feature requests...

Regarding the -c option bug: as they say in the last comment, the workaround is to put the -c option after the directories like this:

sphinx-build -M html inputDir outputDir -c configDir (-D options following now in my case)

So if you'd actually add support for multiple -D options and the -c option (after inputDir and outputDir), I'd become a happy Gradle plugin user everafter.

Kind regards, Matthias