This article overviews difficulties and challenges faced by mathematics professors and students at the Riga Technical University due to the necessity of enforced and immediate transition from the classroom to distance learning. It also contains research focused on finding an optimal way of teaching mathematics when only distance education is available. The research is based on surveys completed by students and mathematics professors about the experience gained during the spring and autumn semesters of 2020. The methods found through the research can be applied in teaching related subjects such as natural sciences and engineering.