The Berne Convention on copyright specifies the Right to Quote as an exception to copyright.
Article 10 (1) It shall be permissible to make quotations from a work which has already been lawfully made available to the public, provided that their making is compatible with fair practice, and their extent does not exceed that justified by the purpose, including quotations from newspaper articles and periodicals in the form of press summaries.
(2) It shall be a matter for legislation in the countries of the Union, and for special agreements existing or to be concluded between them, to permit the utilization, to the extent justified by the purpose, of literary or artistic works by way of illustration in publications, broadcasts or sound or visual recordings for teaching, provided such utilization is compatible with fair practice.
But as the second paragraph says, it is up to each country to determine in law how this right to quote shall be specified. Many countries cover this right under their broader rights of fair use or fair dealing. There are also several countries which have not signed the Berne Convention.
So just as you can quote from any random book without a license, you can quote from something GPL licensed without needing to abide by that license. But because the laws implementing the right to quote can be somewhat nebulous, and not every country has laws explicitly permitting it, I'd recommend you only quote the minimum you need.
Note that the right to quote applies to quotes in literature, and doesn't apply to using copied code in other software. When you copy code to use it in software there's no minimum amount of code that means you wouldn't be bound by its license. It's possible that you could make an argument that the copied code is too trivial to be copyrightable but it might be expensive to attempt to defend such an argument in court, and if the code really is so trivial then you should be able to reimplement it instead of copying it. But this is a different situation to quoting some code in an academic text.