I am studying the cost of debt. Without loss of generality, suppose the debt consists of bonds. On the one hand, some textbooks (e.g. Hillier et al. "Fundamentals of Corporate Finance: 4th European Edition" chapter 13) warn against using coupon rate as the cost of debt, as the coupon rate is relative to the face value, not the market value of the bond. Instead, they suggest using yield to maturity (YTM) which is the compound return calculated relative to the bond's market value, and that makes sense to me. (Berk & DeMarzo "Corporate Finance" 4th ed. includes a similar point among "Common Mistakes" in Chapter 12.)
On the other hand, when calculating the weighted average cost of capital (WACC), the cost of debt is typically multiplied by $(1-t)$ where $t$ is the tax rate. This is meant to account for the fact that interest payments are tax deductible. This would make sense to me if the cost of debt were the coupon rate but not YTM. Whenever YTM times the market value of the bond is not the same as the coupon, I do not see why the difference should be tax deductible. After all, the actual payments that the tax office gets to see and to give tax deductions for are the coupons, not YTM times the market value of the bond. So multiplication by $(1-t)$ does not make sense to me any longer.
How should I think about this?