McGraw-Hill and Cengage plan to merge in a deal that would create the second-largest provider of college textbooks and other higher-education materials in the country.

The closely held companies, formally known as McGraw-Hill Education Inc. and Cengage Learning Holdings II Inc., are billing the all-stock deal as a rare merger of equals, which would set them up to better compete as the rise of digital books and course materials pressures their businesses.

The deal, should it pass muster with regulators, would create a new company with roughly $3.16 billion in annual revenue, McGraw-Hill and Cengage’s chief executives said in an interview Tuesday. The new company is to be called McGraw Hill and will be led by Cengage CEO Michael Hansen.

Based on revenue multiples of publicly traded rivals, it could be valued at around $5 billion, trailing the roughly $8.5 billion market capitalization of London-based Pearson PLC, the biggest player in the U.S. higher-education market.

The deal comes as textbook publishers are adjusting to a changing educational landscape in which low-cost alternatives are often available online. About half of both companies’ sales still come from traditional print textbooks, while the rest is from digital books and class materials such as online homework assignments, and combining could help them make much-needed cost reductions.