If one buys 30 year bonds directly from the treasury, I understand the semi-annual interests are taxable at federal level. But what about capital gains in case the bonds are purchased at a discount from the face value. How exactly are they taxed?
When any non-exempt bond (not just Treasuries) is bought at more than a 'de minimis' discount, the 'guaranteed' gain is treated for tax purposes as additional interest, amortized over the term of the bond (if more than one year). See the section Discount on Debt Instruments in chapter 1 of publication 550, downloadable in PDF or on the web (IDK why 2017 isn't up yet, but this provision hasn't changed recently). Although the actual computations are fairly complicated (see also pub 1212), if you hold the bond through a financial institution like a broker -- or TreasuryDirect, which is actually a fiscal agent, IIRC the Pittsburgh FRB -- they will do the computation and provide it to you and the IRS on Form 1099-OID during filing season, and you include it on Schedule B just like 'real' interest on 1099-INT. Marketable Treasuries in particular are book-entry only (since about 2000 IIRC) so you almost have to hold through some institution.
The 'de minimis' threshold is based on the bond's term, and for a 30-year bond is 7.5%; it looks to me like only a few recent 30-year auctions exceeded that (and both were reopenings, which you could simply avoid). Under the threshold you just report it as a capital gain at redemption or sale whichever comes first, in the usual fashion. I don't recall if TreasuryDirect issues you a 1099-B but if not this case is simple enough to do by hand (no transaction costs, no account costs, no margin, no basis adjustment, ...).