early 15c., "a composition, a chronicle, the entire text of a writing," from Latin contextus "a joining together," originally past participle of contexere "to weave together," from assimilated form of com "with, together" (see con-) + texere "to weave, to make" (from PIE root *teks- "to weave," also "to fabricate").
Meaning "the parts of a writing or discourse which precede or follow, and are directly connected with, some other part referred to or quoted" is from 1560s.
<a href="https://www.etymonline.com/word/contex">Etymology of contex by etymonline</a>
Harper, D. (n.d.). Etymology of contex. Online Etymology Dictionary. Retrieved $(datetime), from https://www.etymonline.com/word/contex