A literate program is a set of of source files each containing a mix of documentation (e.g. as Latex 'code') and code (e.g. as C++ code -- https://en.wikipedia.org/wiki/Literate_programming). From them one can generate a PDF (for instance) containing the documentation and the source code listing. One can also extract the source code and compile it into a usable binary.

How can these literate source files be licensed, such that the PDF resulting from them - containing the source code listing - can be distributed freely for non-commercial use (e.g. with a Creative Commons BY-NC-SA), while the program extracted from them is ``open source'' (e.g. GPL, BSD, etc), and the literate source files themselves can be distributed with something like a BY-NC-SA too?

2 Answers 2


My first thought was to suggest making the file self-documenting: that is, the resulting PDF, while clearly declaring itself CC BY-NC-SA, would make it clear in the appropriate places that the source code contained therein was available under a free licence. Then I realised that was a lot of effort, and frankly complex, likely to go wrong, and unlikely to be of much use to most people.

I suggest that you make the literate source file CC BY-NC-SA, and make the resulting PDF output CC BY-NC-SA in its entirety (which is implicit, but there's no harm in clearly saying it). But distribute the source code, on its own, separately, under the free licence you prefer. For maximum utility, make it clear in the PDF that the program source can be had under free terms from insert-your-URL-here.

  • If the literate source files are CC BY-NC-SA and the source code extracted from it is also licensed under GPLv3 (for instance), doesn't it mean that the source code part has a dual license, and that users could choose to use one or the other? This would not be good since CC is not adapted for software. Dec 22, 2023 at 14:33
  • 1
    No. It would mean that if you took it from the PDF or LaTeX source, you could use it only under CC BY-NC-SA (which, in addition to a non-code-friendly licence, is a non-free licence, so we don't care about that). If you took it from the repository, you could use it only under GPL (or whatever free licence it was distributed under, from there). Don't make the mistake of thinking licences inhere in code; they don't.
    – MadHatter
    Dec 22, 2023 at 15:03
  • 1
    This gets very awkward if you e.g. receive a pull request to the FOSS repo, and you want to embed the resulting code into the PDF (because the author of that code did not give you permission to place it under CC-BY-NC-SA). You might need something resembling a CLA to make it work. Or at least, some kind of contributor agreement, anyway.
    – Kevin
    Dec 23, 2023 at 4:00
  • True, though it's equally true for nearly all dual-licensing setups.
    – MadHatter
    Dec 23, 2023 at 13:34
  • Still, users could choose to extract the code from the PDF and use it with CC BY-NC-SA. Since this license is not recommended for software, I would like to be sure this is OK, in particular for me. It seems the license has a ''no warranty'' section which protects me, like GPL, BSD, etc. But maybe there are other issues? Dec 24, 2023 at 9:09

To my understanding, the tools used in literate programming need some kind of marker to know what is compilable source code and what is documentation. My approach would be to give the literate programming source one license and to give the compilable source an additional license, using the marker system to indicate which parts are subject to the second license.

As an example, this could look like

This literate programming project is licensed under the CC BY-SA 4.0 license. Additionally, the source code, which is delimited by the <<...>>= and @ lines in the literate programming source, can be used under the 3-clause BSD license.

If you want to have the compilable source under a copyleft license like the GPL, then it might be better to either have the complete project under that license or to distribute the compilable source separately (as mentioned in the answer by @MadHatter), to make it easier on the downstream distributors to comply with the requirement that they must make the source code available.

  • Is it possible to use two licenses for a single file, one for the documentation part only and another for the source code part only? If so, how should this be phrased? To me your example means that the source code has a dual license, because the CC license is for "the literate programming project" (as a whole, hence including the source code). I guess that to distribute such a file, one would need to comply to both licenses at the same time? Dec 22, 2023 at 14:35
  • 1
    Yes, if you can clearly indicate which part of a file is subject to which license, then you can apply different licences to different parts of a file. In mu example, the source code is indeed dual-licensed, because the PDF will likely also contain a copy of the source code and it is so much easier if you can comply with just one license on the PDF. Dec 22, 2023 at 18:23
  • 2
    If different parts of a file are licensed under different licenses, then you need to follow all licenses when distributing the complete file. If parts are dual-licensed, then a recipient cam choose for those parts which of the license choices to follow (or to follow both of them). Dec 22, 2023 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.